1.
This program will allocate the memory of ___ bytes for pointer “ptr”.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *ptr;
ptr = realloc(0,sizeof(int)*10);
return 0;
}
Answer: Option 'C'
40
2.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *ptr;
free(ptr);
return 0
}
Answer: Option 'C'
Aborted (core dumped)
3.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
struct st{
int a;
char b;
};
int main()
{
struct st *st_ptr;
st_ptr = malloc(sizeof(struct st));
printf("%d\n",sizeof(struct st));
return 0;
}
Answer: Option 'A'
8
4.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *ptr;
ptr = (char *)malloc(sizeof(char)*11);
ptr = "sanfoundry";
printf("%s\n",*ptr);
return 0;
}
Answer: Option 'B'
segmentation fault
5.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *ptr;
memcpy(ptr,"sanfoundry",11);
printf("%s\n",ptr);
return 0;
}
Answer: Option 'B'
segmentation fault
6.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *ptr;
ptr = (char*)malloc(sizeof(char)*11);
strcpy(ptr,"sanfoundry");
printf("%d\n",*ptr);
return 0;
}
Answer: Option 'C'
115
7.
Which one of the following in true about this program?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *ptr;
printf("%p\n",ptr);
ptr = (char *)malloc(sizeof(char));
printf("%p\n",ptr);
return 0;
}
Answer: Option 'D'
none of these
8.
In this program the two printed memory locations has the difference of ___ bytes.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *ptr;
ptr = (int*)malloc(sizeof(int)*2);
printf("%p\n",ptr);
printf("%p\n",ptr+1);
return 0;
}
Answer: Option 'B'
4
9.
What is the output of this program?
#include<stdio.h>
#inlcude<stdlib.h>
int main()
{
int *ptr;
double *ptr;
printf("%d\n",sizeof(ptr));
return 0;
}
Answer: Option 'C'
the compiler will give the error
10.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int ptr;
ptr = (int)malloc(sizeof(int)*10);
return 0;
}
Answer: Option 'D'
none of these