KEMBAR78
Pointer in c program | PPTX
Pointer in C
A pointer is a variable whose value is the address of another variable, i.e., direct address
of the memory location.
What is pointer ?
7866321
Pointer variable Normal variable
int *a int b
Address: 7865321 Address: 7866321
Pointers in C language is a variable that stores/points the address of another variable.
A Pointer in C is used to allocate memory dynamically i.e. at run time.
The pointer variable might be belonging to any of the data type such as int, float, char,
double, short etc.
Like any variable or constant, you must declare a pointer before using it to store any
variable address.
What is pointer ?
The general form of a pointer variable declaration is
What is pointer ?
type *var_name;
Take a look at some of the valid
pointer declarations −
int *ip; /* pointer to an integer */
double *dp; /* pointer to a double */
float *fp; /* pointer to a float */
char *ch /* pointer to a character */
There are a few important operations, in pointer
• (a) define a pointer variable,
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
• (b) assign the address of a variable to a pointer
ip = &var; /* store address of var in pointer variable*/
• (c) finally access the value at the address available in the pointer variable.
This is done by using unary operator * that returns the value of the variable
located at the address specified by its operand.
*ip /* access the value using the pointer */
How to Use Pointers?
#include <stdio.h>
int main () {
int var = 20;
int *ip;
ip = &var;
printf("Address of var variable: %xn", &var );
printf("Address stored in ip variable: %xn", ip );
printf("Value of *ip variable: %dn", *ip );
return 0;
}
How to Use Pointers?
#include <stdio.h>
int main () {
int var = 20; /* actual variable declaration */
int *ip;
ip = &var;
printf("Address of var variable: %xn", &var );
printf("Address stored in ip variable: %xn", ip );
printf("Value of *ip variable: %dn", *ip );
return 0;
}
How to Use Pointers?
#include <stdio.h>
int main () {
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &var;
printf("Address of var variable: %xn", &var );
printf("Address stored in ip variable: %xn", ip
printf("Value of *ip variable: %dn", *ip );
return 0;
}
How to Use Pointers?
#include <stdio.h>
int main () {
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &var; /* store address of var in pointer variable*/
printf("Address of var variable: %xn", &var );
printf("Address stored in ip variable: %xn", ip );
printf("Value of *ip variable: %dn", *ip );
return 0;
}
How to Use Pointers?
#include <stdio.h>
int main () {
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &var; /* store address of var in pointer variable*/
printf("Address of var variable: %xn", &var ); /* print the Address of var variable*/
printf("Address stored in ip variable: %xn", ip );
printf("Value of *ip variable: %dn", *ip );
return 0;
}
How to Use Pointers?
#include <stdio.h>
int main () {
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &var; /* store address of var in pointer variable*/
printf("Address of var variable: %xn", &var ); /* print the Address of var variable*/
printf("Address stored in ip variable: %xn", ip ); /* address stored in pointer variable */
printf("Value of *ip variable: %dn", *ip ); /* access the value using the pointer */
return 0;
}
How to Use Pointers?
#include <stdio.h>
int main () {
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &var; /* store address of var in pointer variable*/
printf("Address of var variable: %xn", &var ); /* print the Address of var variable*/
printf("Address stored in ip variable: %xn", ip ); /* address stored in pointer variable */
printf("Value of *ip variable: %dn", *ip ); /* access the value using the pointer */
return 0;
}
Reference operator (&) and Dereference operator (*)
& is called reference operator. It gives you the address of a variable.
Likewise, there is another operator that gets you the value from the address, it is called
a dereference operator (*).
Note: The * sign when declaring a pointer is not a dereference operator. It is just a
similar notation that creates a pointer.
How to Use Pointers?
#include <stdio.h>
int main () {
int var = 20;
int *ip; /* reference operator. */
ip = &var;
printf("Address of var variable: %xn", &var );
printf("Address stored in ip variable: %xn", ip );
printf("Value of *ip variable: %dn", *ip );
return 0;
}
How to Use Pointers?
#include <stdio.h>
int main () {
int var = 20;
int *ip; /* reference operator. */
ip = &var;
printf("Address of var variable: %xn", &var );
printf("Address stored in ip variable: %xn", ip );
printf("Value of *ip variable: %dn", *ip ); /* dereference operator */
return 0;
}

Pointer in c program

  • 1.
  • 2.
    A pointer isa variable whose value is the address of another variable, i.e., direct address of the memory location. What is pointer ? 7866321 Pointer variable Normal variable int *a int b Address: 7865321 Address: 7866321
  • 3.
    Pointers in Clanguage is a variable that stores/points the address of another variable. A Pointer in C is used to allocate memory dynamically i.e. at run time. The pointer variable might be belonging to any of the data type such as int, float, char, double, short etc. Like any variable or constant, you must declare a pointer before using it to store any variable address. What is pointer ?
  • 4.
    The general formof a pointer variable declaration is What is pointer ? type *var_name; Take a look at some of the valid pointer declarations − int *ip; /* pointer to an integer */ double *dp; /* pointer to a double */ float *fp; /* pointer to a float */ char *ch /* pointer to a character */
  • 5.
    There are afew important operations, in pointer • (a) define a pointer variable, int var = 20; /* actual variable declaration */ int *ip; /* pointer variable declaration */ • (b) assign the address of a variable to a pointer ip = &var; /* store address of var in pointer variable*/ • (c) finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand. *ip /* access the value using the pointer */
  • 6.
    How to UsePointers? #include <stdio.h> int main () { int var = 20; int *ip; ip = &var; printf("Address of var variable: %xn", &var ); printf("Address stored in ip variable: %xn", ip ); printf("Value of *ip variable: %dn", *ip ); return 0; }
  • 7.
    How to UsePointers? #include <stdio.h> int main () { int var = 20; /* actual variable declaration */ int *ip; ip = &var; printf("Address of var variable: %xn", &var ); printf("Address stored in ip variable: %xn", ip ); printf("Value of *ip variable: %dn", *ip ); return 0; }
  • 8.
    How to UsePointers? #include <stdio.h> int main () { int var = 20; /* actual variable declaration */ int *ip; /* pointer variable declaration */ ip = &var; printf("Address of var variable: %xn", &var ); printf("Address stored in ip variable: %xn", ip printf("Value of *ip variable: %dn", *ip ); return 0; }
  • 9.
    How to UsePointers? #include <stdio.h> int main () { int var = 20; /* actual variable declaration */ int *ip; /* pointer variable declaration */ ip = &var; /* store address of var in pointer variable*/ printf("Address of var variable: %xn", &var ); printf("Address stored in ip variable: %xn", ip ); printf("Value of *ip variable: %dn", *ip ); return 0; }
  • 10.
    How to UsePointers? #include <stdio.h> int main () { int var = 20; /* actual variable declaration */ int *ip; /* pointer variable declaration */ ip = &var; /* store address of var in pointer variable*/ printf("Address of var variable: %xn", &var ); /* print the Address of var variable*/ printf("Address stored in ip variable: %xn", ip ); printf("Value of *ip variable: %dn", *ip ); return 0; }
  • 11.
    How to UsePointers? #include <stdio.h> int main () { int var = 20; /* actual variable declaration */ int *ip; /* pointer variable declaration */ ip = &var; /* store address of var in pointer variable*/ printf("Address of var variable: %xn", &var ); /* print the Address of var variable*/ printf("Address stored in ip variable: %xn", ip ); /* address stored in pointer variable */ printf("Value of *ip variable: %dn", *ip ); /* access the value using the pointer */ return 0; }
  • 12.
    How to UsePointers? #include <stdio.h> int main () { int var = 20; /* actual variable declaration */ int *ip; /* pointer variable declaration */ ip = &var; /* store address of var in pointer variable*/ printf("Address of var variable: %xn", &var ); /* print the Address of var variable*/ printf("Address stored in ip variable: %xn", ip ); /* address stored in pointer variable */ printf("Value of *ip variable: %dn", *ip ); /* access the value using the pointer */ return 0; }
  • 13.
    Reference operator (&)and Dereference operator (*) & is called reference operator. It gives you the address of a variable. Likewise, there is another operator that gets you the value from the address, it is called a dereference operator (*). Note: The * sign when declaring a pointer is not a dereference operator. It is just a similar notation that creates a pointer.
  • 14.
    How to UsePointers? #include <stdio.h> int main () { int var = 20; int *ip; /* reference operator. */ ip = &var; printf("Address of var variable: %xn", &var ); printf("Address stored in ip variable: %xn", ip ); printf("Value of *ip variable: %dn", *ip ); return 0; }
  • 15.
    How to UsePointers? #include <stdio.h> int main () { int var = 20; int *ip; /* reference operator. */ ip = &var; printf("Address of var variable: %xn", &var ); printf("Address stored in ip variable: %xn", ip ); printf("Value of *ip variable: %dn", *ip ); /* dereference operator */ return 0; }