Linux Startup and Shutdown Question:
Download Questions PDF

What is the output of this program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
int *ptr1;
while(1){
ptr1 = malloc(1024*1024);
if(ptr1 == 0)
break;
sleep(1);
printf("googlen");
free(ptr1);
}
return 0;
}
a) it will print "google" until the process has been stopeed by any signal
b) it will print nothing
c) segmentation fault
d) none of the mentioned

Answer:

a) it will print "google" until the process has been stopeed by any signal
Explanation:
None.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
google
google
google
google
google
^Z
[10]+ Stopped ./san
[root@localhost google]#

Download Linux Shutdown & Startup Interview Questions And Answers PDF

Previous QuestionNext Question
What is the output of this program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
int ret;
int *ptr;
ptr = (int *)malloc(sizeof(int)*10);
free(ptr);
free(ptr);
return 0;
}
a) it will print nothing
b) it will give segmentaion fault
c) undefined behaviour
d) none of the mentioned
What is the output of this program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
int *ptr1, *ptr2;
ptr1 = malloc(4);
*ptr1 = 10;
*ptr2 = free(ptr1);
printf("%dn",*ptr2);
return 0;
}
a) 10
b) it will print the address stored in ptr1
c) it will print the address stored in ptr2
d) it will give an error