In this program the two printed memory locations has the difference of ___ bytes. [code] #include<stdio.h> #include<stdlib.h>

In this program the two printed memory locations has the difference of ___ bytes.
Code:
   #include<stdio.h>
   #include<stdlib.h>
   int main()
   {
       int *ptr;
       ptr = (int*)malloc(sizeof(int)*2);
       printf("%p\n",ptr);
       printf("%p\n",ptr+1);
       return 0;
   }
A. 1
B. 4
C. can not be determined
D. none of the mentioned
 
Answer: b
Explanation: Pointer will increment by 4 bytes because it is the types of integer.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
0x9b4e008
0x9b4e00c
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top