Consider the following three C functions :
[PI] int * g (void)
{
int x= 10;
return (&x);
}
[P2] int * g (void)
{
int * px;
*px= 10;
return px;
}
[P3] int *g (void)
{
int *px;
px = (int *) malloc (sizeof(int));
*px= 10;
return px;
}
Which of the above three functions are likely to cause problems with pointers?
Answer: C
No answer description available for this question.
Enter details here
What is the output of this program?
#include
#include
int main()
{
int i, numbers[1];
numbers[0] = 15;
free(numbers);
printf("Stored integers are ");
printf("numbers[%d] = %d ", 0, numbers[0]);
return 0;
}
Answer: A
he memory allocation function free() will not free or delete the content in the memory location, because free() can only free or delete the content in the memory, who's memory is allocated either by malloc() or calloc().
Enter details here
Point out the correct statement which correctly free the memory pointed to by 's' and 'p' in the following program?
#include
#include
int main()
{
struct ex
{
int i;
float j;
char *s
};
struct ex *p;
p = (struct ex *)malloc(sizeof(struct ex));
p->s = (char*)malloc(20);
return 0;
}
Answer: B
No answer description available for this question
Enter details here
What is the return type of malloc() or calloc()
Answer: A
No answer description available for this question.
Enter details here
malloc() returns a NULL if it fails to allocate the requested memory.
Answer: A
No answer description available for this question
Enter details here
What will be the output of the program?
#include
#include
int main()
{
char *s;
char *fun();
s = fun();
printf("%s\n", s);
return 0;
}
char *fun()
{
char buffer[30];
strcpy(buffer, "RAM");
return (buffer);
}
Answer: B
The output is unpredictable since buffer is an auto array and will die when the control go back to main. Thus s will be pointing to an array , which not exists.
Enter details here
What is the output of this program?
#include
void main()
{
int *ptr = (int *)malloc(sizeof(int));
*ptr = 10;
free(ptr);
p = 5;
printf("%d", ptr);
}
Answer: B
free() will not deallocate the memory it just to delete all data's allocated to a variable (ptr). In this program, first integer value 10 is assigned to the pointer variable *ptr and then its data is deleted using free(ptr) and then new integer value 5 is assigned to the variable ptr and then 5 is outputted.
Enter details here
What is the problem with following code?
#include
int main()
{
int *p = (int *)malloc(sizeof(int));
p = NULL;
free(p);
}
Answer: B
No answer description available for this question.
Enter details here
Which statment is true about the given code ?
#include
#include
int main()
{
int *a[5];
a = (int*) malloc(sizeof(int)*5);
free(a);
return 0;
}
Answer: B
None
Enter details here
Where does the uninitialized data gets stored in memory?
Answer: C
BSS- Block started by symbol the uninitialized data gets stored in memory.
Enter details here