Pointers in C programming
Pointers in C...
In this section contains example programs demonstrating the use of pointers.
- Pointers in C language is a variable that stores or points the address of another variables.
- A Pointer in C is used to allocate memory dynamically mean at run time. The pointer variable might be belong to any of the datatype i.e. int, float, char, double, short etc.
Syntax : data_type *var_name; Example : int *p; char *p;
here, * is used to denoted that “p” is pointer variable and not a normal variableNormal variable stores the value whereas pointer variable stores the address of the variables.
- In c The content of the C pointer always be a whole number i.e. address.
- Always C pointer is initialized to null mean zero, i.e. int *p = null.
- value of null pointer is 0.
- & symbol is used to get the address of the variable.
- * symbol is used to get the value of the variable that the pointer is pointing to.
- If a pointer in C is assigned to NULL, it means it is pointing to nothing.
- Two pointers can be subtracted to know how many elements are available beetween these two pointers.
- Pointer addition, multiplication, division are not allowed.
- size of any pointer is 2 byte (for 16 bit compiler).
#include <stdio.h>
int main()
{
int *ptr, q;
q = 30;
/* address of q is assigned to ptr */
ptr = &q;
/* display q's value using ptr variable */
printf("%d", *ptr);
return 0;


No comments:
Post a Comment