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

Popular posts from this blog

C Programming #8 (Case Control Instruction)

In Programming we come across some situations where we have to choose from number of alternatives and choice should be specific to condition so the control statement that allow us to make a decision from number of choice is called as switch or we can say switch-case as they are used together. The switch statement looks like : switch (integer expression) { case constant 1: do this; case constant 2: do this; case constant 3: do this; default: do this; } In these case do this is the command statement that is to be followed when case is satisfied Example: #include<stdio.h> int main() { int i=2; switch(i) { case 1: printf("I am in case 1\n"); case 2: printf("I am in case 2\n"); case 3: printf("I am in case 3\n"); default: printf("I am in default"); } return 0; } Output of the program will be : I am in case 2 I am in case 3 I am in default But this is not the output we needed this program should give us...