Wednesday, 3 May 2017

Pointer



C Pointers

The pointer in C language is a variable, it is also known as locator or indicator that points to an address of a value.
c pointers

Advantage of pointer

1) Pointer reduces the code and improves the performance, it is used to retrieving strings, trees etc. and used with arrays, structures and functions.
2) We can return multiple values from function using pointer.
3) It makes you able to access any memory location in the computer's memory.

Usage of pointer

There are many usage of pointers in c language.

1) Dynamic memory allocation

In c language, we can dynamically allocate memory using malloc() and calloc() functions where pointer is used.

2) Arrays, Functions and Structures

Pointers in c language are widely used in arrays, functions and structures. It reduces the code and improves the performance.

Symbols used in pointer

Symbol Name Description
& (ampersand sign) address of operator determines the address of a variable.
* (asterisk sign) indirection operator accesses the value at the address.

Address Of Operator

The address of operator '&' returns the address of a variable. But, we need to use %u to display the address of a variable.
  1. #include <stdio.h>      
  2. #include <conio.h>    
  3. void main(){      
  4. int number=50;    
  5. clrscr();      
  6. printf("value of number is %d, address of number is %u",number,&number);  
  7. getch();      
  8. }      

Output

value of number is 50, address of number is fff4  





1 comment:

Please write your view and suggestion....