Home » C programming language

The Address of (&) and dereference (*) operators with the pointers in C

C language pointers - Address of (&) and dereference operators: Here, we are going to learn about the address of (&) and dereference (*) operators with the pointers in C.
Submitted by IncludeHelp, on November 01, 2018

Here, we are discussing about the two most useful operators with the pointers, why and how they are used?

1 ) The Address of Operator (&)

It is an "address of" operator which returns the address of any variable. The statement &var1 represents the address of var1 variable. Since it can be used anywhere but with the pointers, it is required to use for initializing the pointer with the address of another variable.

2 ) The Dereference Operator (*)

It is used for two purposes with the pointers 1) to declare a pointer, and 2) get the value of a variable using a pointer.

Read more: Accessing the value of a variable using pointer in C

Example:

#include <stdio.h>

int main(void)
{
	//normal variable
	int num = 100;      

	//pointer variable
	int *ptr;           

	//pointer initialization
	ptr = &num;         

	//printing the value
	printf("value of num = %d\n", *ptr);

	//printing the addresses
	printf("Address of num: %x\n", &num);
	printf("Address of ptr: %x\n", &ptr);

	return 0;
}

Output

value of num = 100
Address of num: 9505c134
Address of ptr: 9505c138





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.