Tuesday, November 24, 2015

Pointer and Reference in C Programming Language

Hey, fellas! Long time no see yaa~ In this post, I will tell u about pointer and reference in C programming language! Yeay!
Pointer
First, let me tell you "what is pointer?". Pointer is data type that can hold the address of a variable. When we should use pointer in C programming language? When we need to change a variable content on another's function, to create dynamic data stuctures, to pass and handle variable parameters passed to functions, and to access information stored in arrays.
What is the syntax to declare the pointer?

          data_type : It specifies the type of the pointer. This type specifies the type of variable
                             whose address this pointer can store.
          pointer_variable_name : It can be any name specified by the user (us). The pointer names
                                                  commonly start with 'p' or 'ptr'.
 There are some example for the valid pointer declarations:


This is an example using pointer in c


The output is



 There may be a situation when we want to maintain an array which can store pointer to another data type. How to declare array of pointer in C?


From the example above, we know that it declares ptr as an array of ARRAY integer pointers.
Now I will show you the example about array of pointer.
 
The output will show
l
C programming allows passing a pointer to a function also allows returning a pointer to a function.
To allows passing a pointer to a function is so simple, just declare the function parameter as a pointer type. To returning a pointer to a function, you will have to declare a function returning a pointer. It is so bad to return the address of a local variable outside the function.

References operator (&)
If x is a variable then, &x is the address in memory.
You have already used reference operator in C programming language while using scanf() function.

This is a video for help your learning about pointer
C programming Pointers fully explained 

No comments:

Post a Comment