×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

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

Related Tutorials



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.