What is a Pointer in C | Structure Pointer in C | Function Pointer in C
Pointer in C: A pointer is a variable that contain the address of another variable. we can say that the pointer "points to" another variable.
A pointer is a special type of variable which is used to store the address of another variable. It can be store the address of same data type means an integer pointer can be store the address of integer variable, Character pointer can store the address of character variable.
Pointer in C Programming | Pointer Simplest | Null Pointer |
Pointer denoted by asterisk(*) symbol with any variable at the time of declaring variable then this variable is called pointer variable.
We can use ampersand symbol to get the address of the variable. asterisk(*) symbol is used to get the value at the address which is hold by pointer.
Pointer in C syntax
int a; -> normal Variable int *p;-> pointer variable int a=100; int *p; p=&a; |
Pointer in C Language with Example
#include<stdio.h> #include<conio.h> int main() { int a=10; int *p; p=&a; printf("Value of a:%d\n",a); printf("Address of a:%u\n",&a); printf("Value of p:%d\n",p); printf("Address of p:%u\n",&p); printf("Value of *p:%d\n",*p); getch(); } **********OUTPUT********** Value of a:10 Address of a:8284 Value of p:10 Address of p:8284 Value of *p:10 |
Function Pointer in C Programming Language
Function Pointer in C syntax
return_type (*ptr_name)(parameter_list); |
Function Pointer in C Language with Example
#include<stdio.h> #include<conio.h> void area(int *h,int *w) { int ar=*h * *w; printf("Area of Rectangle:%d",area); } void main() { int x,y; printf("Enter Height:"); scanf("%d",&x); printf("Enter Width:"); scanf("%d",&y); area(&x,&y); getch(); } **********OUTPUT********** Enter Height:12 Enter Width:13 Area of Rectangle:156 |
Pointer To Array in C Programming
Array Pointer in C syntax
data_type (*ptr_name)[num_elements]; |
Array Pointer in C Language with Example
#include<stdio.h> #include<conio.h> void main() { int a[10]={1,2,3,4,5,6,7,8,9}; for(i=0;i<9;i++) { printf("%d ",*(a+i)); } getch(); } **********OUTPUT********** 1 2 3 4 5 6 7 8 9 |
Structure Pointer in C Programming
Structure Pointer in C syntax
struct struct_name *ptr_name; |
Structure Pointer in C Language with Example
#include <stdio.h> #include<conio.h> struct student { char name[50]; int roll; float marks; }; void main() { struct student s = {"Learn Coding", 1938, 80.5}; struct student *p = &s;
printf("Name: %s\n", p->name); printf("Roll number: %d\n", p->roll); printf("Marks: %.2f\n", p->marks);
getch(); } **********OUTPUT********** Name:Learn Coding Roll number: 1938 Marks: 80.50 |
Null Pointer in C Programming
Null Pointer in C Language with Example
#include <stdio.h> #include<conio.h> #include <stddef.h> void main() { int *ptr = NULL;
if (ptr == NULL) { printf("The pointer is null\n"); } else { printf("The pointer is not null\n"); }
getch(); } **********OUTPUT********** The pointer is null |
0 Comments