Computer Sciences > Gate 2017 Set-1 > Pointer
Consider the following C code:
The code suffers from which one of the following problems:
#include<stdio.h>
int * assignval (int *x, int val)
{
*x = val;
return x;
}
int main()
{
int *x = malloc(sizeof(int));
if (NULL == x) return;
x = assignval(x, 0);
if(x)
{
x = (int*) malloc(sizeof (int));
if (NULL == x) return;
x = assignval (x, 10);
}
printf("%dn", *x);
free(x);
}
int * assignval (int *x, int val)
{
*x = val;
return x;
}
int main()
{
int *x = malloc(sizeof(int));
if (NULL == x) return;
x = assignval(x, 0);
if(x)
{
x = (int*) malloc(sizeof (int));
if (NULL == x) return;
x = assignval (x, 10);
}
printf("%dn", *x);
free(x);
}
The code suffers from which one of the following problems:
Correct : Pointer
Similar Questions
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char *argv[])
{
int x = 1, z[2] = {10, 11};
...
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char *argv[])
{
int x = 1, z[2] = {10, 11};
...
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char *argv[])
{
int x = 1, z[2] = {10, 11};
...
Total Unique Visitors
Loading......