What is the output of this program? [code] #include<stdio.h> #include<stdlib.h> #include<string.h>

What is the output of this program?
Code:
   #include<stdio.h>
   #include<stdlib.h>
   #include<string.h>                              
   int main()
   {
       char *ptr;
       memcpy(ptr,"123hoidap",11);
       printf("%s\n",ptr);
       return 0;
   }
A. sanfoudry
B. segmentation fault
C. syntax error
D. none of the mentioned
 
Answer: b
Explanation: Memory must be allocated to pointer “ptr”.
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