Linux Startup and Shutdown Question:
Download Questions PDF

In which condition this prgram will print the string "google"?

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

int main()
{
int *ptr;
ptr = (int *)malloc(sizeof(int)*10);
if (ptr == NULL)
printf("googlen");
return 0;
}
a) if the memory could not be allocated to the pointer "ptr"
b) if the memory has been allocated to the pointer "ptr" successfully
c) it will never print
d) none of the mentioned

Linux Shutdown & Startup Interview Question
Linux Shutdown & Startup Interview Question

Answer:

a) if the memory could not be allocated to the pointer "ptr"
Explanation:
The malloc() returns NULL when the memory is not allocated.

Download Linux Shutdown & Startup Interview Questions And Answers PDF

Previous QuestionNext Question
Program given below will allocate the memory of ___ bytes for pointer "ptr".

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

int main()
{
int *ptr;
ptr = (int*)malloc(sizeof(int)*4);
ptr = realloc(ptr,sizeof(int)*2);
return 0;
}
a) 2
b) 4
c) 8
d) none of the mentioned
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