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

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