



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




RAM (random access memory) is the place in a computer where the operating system, application programs, and data in current use are kept so that they can be quickly reached by the computer's processor. RAM is much faster to read from and write to than the other kinds of storage in a computer, i.e. the hard disk, floppy disk, and CD-ROM. However, the data in RAM stays there only as long as your computer is running. When you turn the computer off, RAM loses its data. When you turn your computer on again, your operating system and other files are once again loaded into RAM, usually from your hard disk.
RAM is the best known form of computer memory. RAM is considered "random access" because you can access any memory cell directly if you know the row and column that intersect at that cell.
Every byte in Ram has an address.
00000000 00000000 00000000 00000001
00000000 00000010
... ... ... ... 11111111 11111111
Essentially, the computer's memory is made up of bytes. Each byte has a number, an address, associated with it. “Pointer is a kind of variable whose value is a memory address, typically of another variable”. Think of it as an address holder, or directions to get to a variable.
*int p; int i = 3; p = &i;
In this piece of code, we have taken a pointer to integer denoted by “*p”. In second statement, an integer is declared and initialized by ‘3’. The next step is the most important one. Here we are passing the “Address” of the integer “i” in the pointer. Since pointers hold the variable addresses; so now the pointer “p” contains the address of the integer “i” which has a value of 3.
char x = 'A'; // variable declaration and initialization int y = 32;
char *xPtr = &x; int *yPtr = &y; // pointer declaration and initialization
... xPtr--; //Since char takes 1 byte, and if xPtr has // a value of 108 now it would have a value of // address 107
xPtr++; // pointer would have a value of address 108
Here, we have explained that if we add 1 to a pointer to integer, then that pointer will point to an address two bytes ahead of its current location. Similarly, when we incremented the xPtr, the address it contained is incremented to one value since xPrt is a pointer to integer.
Note:
Value added or subtracted from pointer is first multiplied by size of object it points to
b = p; // ILLEGAL because b is a constant pointer.
**float x[15]; float y = &x[0]; float z = x;
*int ptr; int j = 10;
*ptr = &j; printf ("%d\n", ptr);
**ptr = 15; printf ("%d %d\n", ptr, j);
*if (ptr != 0) { printf ("Pointer ptr points at %d\n", ptr); }
**double d; double ptr_d; char c; char ptr_c; ptr_d = &d; ptr_c = &c; //This operation will skips 8 bytes in memory because ptr_d is a pointer to double. ptr_d = ptr_d + 1; //This operation will skips 1 byte in memory because ptr_c is a pointer to character.
ptr_c = ptr_c +1;
float x[5];
Our memory model is