Linux Startup and Shutdown Question:
Download Questions PDF

Please tell me output of this program?

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

int main()
{
int *ptr;
ptr = (int *)calloc(1,sizeof(int));
if (ptr != 0)
printf("%dn",*ptr);
return 0;
}
a) 0
b) -1
c) garbage value
d) none of the mentioned

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

Answer:

a) 0
Explanation:
The memory allocated by calloc() contains 0 until process does not make any change to it.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
0
[root@localhost google]

Download Linux Shutdown & Startup Interview Questions And Answers PDF

Previous QuestionNext Question
In this program the allocated memory block can store
<pre lang="c" line="1" cssfile="hk1_style">
#include<stdio.h>
#include<stdlib.h>

int main()
{
int *ptr;
ptr = malloc(10);
return 0;
}
a) int
b) char
c) float
d) all of the mentioned
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