Header Ads

                            C Programming -Lecture 12 : Memory operations and pointers


We know that one of the values ??of the variables can be deposited. X as a variable of type int, which will declare that we Rabies
int x;
Now the value of the variables that can keep ints Rabies
x = 100;
However, we have to declare a variable called x 100 for the value of our program will run when the computer is set up memory space for a specific functionality. Suppose this is the location of the memory 40000. If the memory is 4 bytes across 40,000 locations in 100 sakhakhyati will be. We assume here that we've been using the computer for intajara rakhara using 4-byte memory. If we want to find out if it does not bear out the use of the sizeof B-
int int_size = sizeof (int);
We have over 40,000 locations in the variable x, which we now want to find out if we can do it & use. Just the variable name & ayadres paba
printf ( "% d", & x);
The console Locations 40000 (40000 is the true location of the seta, but we assume for convenience) will print.
40000 Thus, if the value of a variable print does not want to keep the deposit if we can keep in a variable of type pointer. Since x is a variable of type int to its location, we normally use pointers to type int. It must be a name similar to another leriyebalera. Thus, the variable we just declared, we can be helpful if px
int * px;
The variable name with the * symbol , we have explained that it is a pointer type variables. With a variable of type int ints and explained that we can not address.
Now we want to keep the location of the variable x in the variable px then this can be helpful to write
px = & x;
If we print the value of px we shall 40000.
Now, if you want to get the value of x using px ebhabe if we can be helpful to write
int v = * px;
V If the value will be credited to the 100 x in which we have previously submitted. Pointer variable points to the location of that name * payenatara are using the locations that have values ??that are available.
Now we learn on top of things, the use of a program karih
#include "stdio.h"

int main ()
{
    int x;
    x = 100;
   printf ( New york times)

    printf ( Value of point).

    return 0;
}
Now I get output like this program is run for the first time.
Address of x = 13434088
px = 13434088
Value of x = 100
I like the following output in the second run.
Address of x = 9959872
px = 9959872
Value of x = 100
So it turns out we have to run every x different locations that we have seen the beginning of the 40000 took over. We have never been to before bastabe can not take the address of a variable (of course if we do not write the operating system program. Lyanguyejai C is used for writing operating systems. Windows, Linux, etc., or the portion of the kernel is written using C Language.).
For better understanding of the above program runs several times by himself. Some changes can parse.
Pointers and arrays
First, we have a program with an array of ints variable likhi
#include "stdio.h"

int main ()

 {   numbers [0] = 56;
    numbers [1] = 25;
    numbers [2] = 87;
px = numbers;
    px = & numbers 0.
    printf ( Second value of point).
   


    px = & numbers 1,
    printf ( Third value of point)
   px = & numbers 2.
  
    return 0;
}
The first (Seep 0) numbers, we declare an array of ints, and 3 pm at number three have ayaretara.
And (Step 1) We have an array of numbers in the address we have px payesatara type variables. Notice the numbers before we did not use the & symbol. This is because the variable of type array, the array itself is the location of the variable.
And (Step 2) We numbers [0] to have the addresses of px. I had to use the & symbol. For the benefit of you not to think of printf ( "% d", numbers [0]) , but the output will be 56 printf ( "% d", numbers) to the output of the address numbers. Where will print the value of the & sign can be used to find out the address.
And for the rest of the two values ??(Step 3,4) code has been written in the same way.
I've run this program twice. For the first time are autaputa
First value of px = 10222376
 value of pixel = 10222376
2nd value of unstable penetrating by = 56

Third value of variable pointed by px = 25
Last value of px = 10222384
Last value of variable pointed by px = 87.

No comments:

Powered by Blogger.