0% found this document useful (0 votes)
127 views

Pointer Operator in C Program

The document discusses C pointer operators. It explains that the * operator returns the value at a given address, while the & operator returns the address of a variable. It provides examples of using these operators, such as printing the address of a variable n and the value stored at that address. The document also discusses how declaring a pointer variable like "int *ptr" tells the compiler that ptr will store the address of an integer variable.

Uploaded by

Deepak Negi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Pointer Operator in C Program

The document discusses C pointer operators. It explains that the * operator returns the value at a given address, while the & operator returns the address of a variable. It provides examples of using these operators, such as printing the address of a variable n and the value stored at that address. The document also discusses how declaring a pointer variable like "int *ptr" tells the compiler that ptr will store the address of an integer variable.

Uploaded by

Deepak Negi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C pointer operator

In the previous chapter we have learnt about finding the size of pointer variable. In this chapter
we will be learning about different pointer operators in C Programming language.

Pointer Operator in C Program :

Operator Operator Name Purpose

* Value at Operator Gives Value stored at Particular address

& Address Operator Gives Address of Variable

In order to create pointer to a variable we use “*” operator and to find the address of variable we
use “&” operator.
[box]Don’t Consider “&” and “*” operator as Logical AND and Multiplication Operator in Case of
Pointer.[/box]

Important Notes :

1. ‘&’ operator is called as address Operator

2. ‘*’ is called as ‘Value at address’ Operator

3. ‘Value at address’ Operator gives ‘Value stored at Particular address.

4. ‘Value at address’ is also called as ‘Indirection Operator’

Pointer Operators : Live Program

#include<stdio.h>

int main()
{
int n = 20;
printf("\nThe address of n is %u",&n);
printf("\nThe Value of n is %d",n);
printf("\nThe Value of n is %d",*(&n));
}

Output:

The address of n is 1002


The Value of n is 20
The Value of n is 20

How *(&n) is same as printing the value of n ?

&n Gives address of the memory location whose name is ‘n’

* means value at Operator gives value at address specified by &n.

m = &n Address of n is stored in m , but remember that m is not ordinary variable like ‘n’

So Ccompiler must provide space for it in memory.Below is Step by Step Calculation to compute
the value –

m = * ( &n )
= * ( Address of Variable 'n')
= * ( 1000 )
= Value at Address 1000
= 20

What Does following declaration tells compiler ?

int *ptr;

1. ‘ptr’ is declared as that ‘ptr’ will be used only for storing the address of the integer valued

variables

2. We can also say that ‘ptr’ points to integer

3. Value at the address contained in ‘ptr’ is integer .

4. Declaration Memory
Explanation
Required

1 int *p p is going to store address of integer value 2 bytes

2 float *q q is going to store address of floating value 2 bytes

ch is going to store address of character


3 char *ch 2 bytes
variable

You might also like