Skip to main content

C Programming #10 (Pointers)


  • Call by value
To understand this you have to be familiar with functions. Whenever we call a function we passed something to it in general we pass values of the variable to call the function
Eg:-
  • sum=calsum(a,b,c);
  • f=factor(a);

  • Call by reference 
To get this topic one concept you have to keep in mind that if we do anything in computer it get stored somewhere in the memory so instead of passing value of the variable if we are able to pass location of number ie:address of number then it is call by reference. If you are still not able to understand it then dont worry it's too tough for beginners but in time you will get the things

Pointer Notation
Consider:-
  • i=3
Here i is the location name
3 is the value of the location
65524 is the location number

To know the address ie location number you can use the program:-
#include<stdio.h>
int main()
{
int i=3;
printf("Address of i=%u\n",&i);
printf("Value of i=%d\n",i);
return 0;
}
As you can see in printf I have used &i so & returns the address of the variable and u in %u is used to print unsigned integer. Similarly pointer has one more operator * it is called as value at the address operator. So if we use  *(&i) at same time so it will print value of i .

Using this concept we can save address of one variable in other and use it so we can access the value of other variable to save address of other variable we have initialize it like int  *j;

Note:-If you want any kind of detail on pointers feel free to ask me in comments.

Comments