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

Lâm Phung

New member
What is the output of this program?
Code:
   #include<stdio.h>
   #include<stdlib.h>
   #include<string.h>                              
   int main()
   {
       char *ptr;
       ptr = (char*)malloc(sizeof(char)*11);
       strcpy(ptr,"123hoidap");
       printf("%d\n",*ptr);
       return 0;
   }
A. s
B. 123hoidap
C. 115
D. segmentation fault
 
Answer: c
Explanation: This program will print the equivalent decimal value at location pointed by “ptr”.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
115
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top