Skip to content

Commit 2701b58

Browse files
committed
pointer
1 parent a8a8ae6 commit 2701b58

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Pointer/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Pointers in C
2+
#### Pointers are variables which store the address of a variable.
3+
#### They have data type just like variables, for example an integer type pointer can hold the address of an integer variable and an character type pointer can hold the address of char variable.
4+
5+
# Example
6+
```
7+
#include <stdio.h>
8+
int main (){
9+
int y = 5;
10+
int *p;
11+
p = &y;
12+
printf("Address of y : %x\n", &y );
13+
printf("Content of p: %x\n", p );
14+
printf("Content of *p: %d\n", *p );
15+
}
16+
17+
int a = 20;
18+
int *p = &a;
19+
```
20+
<img>
21+
22+

Pointer/pointer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include<stdio.h>
2+
int main(){
3+
int number=50;
4+
int *p;
5+
p=&number;//stores the address of number variable
6+
printf("Address of p variable is %x \n",p); // p contains the address of the number therefore printing p gives the address of number.
7+
printf("Value of p variable is %d \n",*p); // As we know that * is used to dereference a pointer therefore if we print *p, we will get the value stored at the address contained by p.
8+
return 0;
9+
}

0 commit comments

Comments
 (0)