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

Android O (Android Operating system)

There are many kind of changes and improvements in this new version of Android OS. Increased Ability of the mobile:- aptX bluetooth streaming :-   High quality audio codec is supported for streaming to bluetooth Headsets and Speakers Adaptive icons give devs and OEMs easy shape masks, extra effects :-  "an OEM like Samsung or HTC will provide a unifying mask, which will allow developers to integrate almost any existing app icon into the broader user interface with minimal effort, and no extra graphics work on the icon itself." Neighborhood Aware Networking (NAN) mode for WiFi :-  "You can think about NAN as a combination of WiFi Direct and Nearby. Two hypothetical phones with NAN could find each other and connect without any additional apps or configuration, allowing them to share data at high speeds." Picture-in-picture video for all devices and new windowing features :- "The gist is that when watching video on Android O, you'll be able to shr...

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...

C Programming #9 (Functions)

Function is a self contained block of statement that perform a coherent task of some kind. In simple word to write a C Program in a professional manner and in a clean way it is must to use  functions. Function is used in the C program where you want to do a specific kind of work always. Example: #include<stdio.h> void message(); int main() { message(); printf("This is 1\n"); return 0; } void message() { printf("This is 2\n"); } Output: This is 2 This is 1 Now you must be wondering that This is 1 Should come first but I have made use of function and designed how it should appear. In this program I have used Message() three times void message() This is for function prototype declaration It is necessary to mention prototype of every function that we intend to define in a program message() This is the function call means it call it's own function and main() is temporarily suspended till the control is in function message af...