Difference between revisions of "Interview Preparation Pointers"

From Embedded Systems Learning Academy
Jump to: navigation, search
Line 7: Line 7:
 
</pre>
 
</pre>
 
The above example , we have declared a pointer to a variable (pointer_to_integer), the variable stores the address of an integer .
 
The above example , we have declared a pointer to a variable (pointer_to_integer), the variable stores the address of an integer .
 +
 +
Code:
 +
<pre>
 +
#include <stdio.h>
 +
 +
int main(void) {
 +
int var = 20;
 +
int *p;
 +
p = &var;
 +
 +
printf("Pointer %d\n",var);
 +
printf("Pointer %d\n",&var);    // Prints the address of the varaible (var)
 +
printf("Pointer %d\n",p);       
 +
printf("Pointer %d\n",*p);     // Prints the value that (p) points to 
 +
return 0;
 +
}
 +
</pre>
 +
  
 
   '''Under_construction'''
 
   '''Under_construction'''

Revision as of 04:35, 5 December 2016

Pointers : A pointer is a variable who's value is address of some other variable i.e. it can be address of some memory location.

<varaible_type> *<name>
eg : 
     int *pointer_to_integer

The above example , we have declared a pointer to a variable (pointer_to_integer), the variable stores the address of an integer .

Code:

#include <stdio.h>

int main(void) {
	int var = 20;
	int *p;
	p = &var;
	
	printf("Pointer %d\n",var);
	printf("Pointer %d\n",&var);     // Prints the address of the varaible (var)
	printf("Pointer %d\n",p);        
	printf("Pointer %d\n",*p);	     // Prints the value that (p) points to   
	return 0;
}


 Under_construction