What is the output of this program? [code] #include<stdio.h> #include<stdlib.h> int main() { int *ptr; *ptr =

Quang Hiếu

New member
What is the output of this program?
Code:
   #include<stdio.h>
   #include<stdlib.h>
   int main()
   {
       int *ptr;
       *ptr = 10;
       *ptr = 20;
       printf("%d\n",*ptr);
       return 0;
   }
A. 10
B. 20
C. segmentation fault
D. none of the mentioned
 
Answer: c
Explanation: The segmentation fault occurs because memory for the pointer has not been allocated in this program.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
Segmentation fault (core dumped)
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top