Saturday, 8 August 2015

Usage of a Pointer in C

HOW TO DECLARE A POINTER ?
A pointer is declared as : 
< pointer type > * < pointer-name > 
In the above declaration : 
1. pointer-type : It specifies the type of pointer. It can be int,char, float etc. This type specifies the type of variable whose address this pointer can store. 
2. pointer-name : It can be any name specified by the user. Professionally, there are some coding styles which every code follows. The pointer names commonly start with ‘p’ or end with ‘ptr’ 
An example of a pointer declaration can be : 
char *chptr; 
In the above declaration, ‘char’ signifies the pointer type, chptr is the name of the pointer while the asterisk ‘*’ signifies that ‘chptr’ is a pointer variable.
How to initialize a Pointer? 
A pointer is initialized in the following way : 
< pointer declaration(except semicolon) > = < address of a variable >
OR
< pointer declaration > 
< name-of-pointer > = < address of a variable > 
Note that the type of variable above...

3 comments: