0% found this document useful (0 votes)
6 views1 page

Pointers

The document explains the concept of pointers in C, highlighting their ability to store memory addresses of variables, functions, and other pointers. It includes two demonstration code snippets that illustrate how to declare pointers, assign addresses, and access values through pointers. The examples show the importance of matching data types between pointers and the variables they reference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Pointers

The document explains the concept of pointers in C, highlighting their ability to store memory addresses of variables, functions, and other pointers. It includes two demonstration code snippets that illustrate how to declare pointers, assign addresses, and access values through pointers. The examples show the importance of matching data types between pointers and the variables they reference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Pointers

● A pointer can be used to store the memory address of other variables, functions, or
even other pointers.
● The use of pointers allows low-level memory access, dynamic memory allocation, and
many other functionality in C.

Demo1:
#include <stdio.h>
int main()
{
int var = 20; // actual variable declaration
int *ptr; // pointer variable declaration
ptr = &var; // store address of var in pointer variable
printf("Address of var variable: %p\n",&var);
printf("Address stored in ptr variable: %p\n",ptr);
printf("Value of *ptr variable: %d\n", *ptr);
return 0;
}

Demo2:
#include <stdio.h>
void display()
{
int var = 10; // declare pointer variable
int* ptr; // note that data type of ptr and var must be same
ptr = &var; // assign the address of a variable to a pointer
printf("Value at ptr = %p \n", ptr);
printf("Value at var = %d \n", var);
printf("Value at *ptr = %d \n", *ptr);
}
int main() {
display();
return 0;
}

You might also like