Typedef
- What will be the output of the following C code?
#include <stdio.h>
typedef struct B
{
int n1, n2;
};
int main()
{
B k = {10, 20};
printf("%d\n", k.n1);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Compilation Error
main.c:5:5: warning: useless storage class specifier in empty declaration
};
^
main.c: In function ‘main’:
main.c:8:9: error: unknown type name ‘B’; use ‘struct’ keyword to refer to the type
B k = {10, 20};
^
struct
main.c:8:20: warning: excess elements in scalar initializer
B k = {10, 20};
^~
main.c:8:20: note: (near initialization for ‘k’)
main.c:9:25: error: request for member ‘n1’ in something not a structure or union
printf("%d\n", k.n1);
- What will be the output of the following C code?
#include <stdio.h>
int (*(a()))[2];
typedef int (*(*p)())[2] ptrfun;
int main()
{
ptrfun p1;
p1 = a;
p1();
return 0;
}
int (*(a()))[2]
{
int (*array)[2] = malloc(sizeof*array);
return &array;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Compilation Error
main.c:3:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ptrfun’
typedef int (*(*p)())[2] ptrfun;
^~~~~~
main.c: In function ‘main’:
main.c:6:9: error: unknown type name ‘ptrfun’
ptrfun p1;
^~~~~~
main.c:7:12: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
p1 = a;
^
main.c:8:9: error: called object ‘p1’ is not a function or function pointer
p1();
^~
main.c:6:16: note: declared here
ptrfun p1;
^~
main.c: In function ‘a’:
main.c:13:27: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
int (*array)[2] = malloc(sizeof*array);
^~~~~~
main.c:13:27: warning: incompatible implicit declaration of built-in function ‘malloc’
main.c:13:27: note: include ‘’ or provide a declaration of ‘malloc’
main.c:14:16: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
return &array;
^~~~~~
main.c:14:16: warning: function returns address of local variable [-Wreturn-local-addr]
- What will be the output of the following C code?
#include <stdio.h>
typedef int integer;
int main()
{
int n1 = 120, *p;
float n2 = 250;
integer k = n1;
p = &k;
printf("%d\n", *p);
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
120
- What will be the output of the following C code?
#include <stdio.h>
typedef struct Employee
{
char *ch;
}Employ;
void main()
{
struct Employee emp;
emp.ch = "Welcome";
printf("%s", emp.ch);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Welcome
- What will be the output of the following C code?
#include <stdio.h>
typedef struct Employee
{
char *ch;
}Employ;
void main()
{
struct Employ emp;
emp.ch = "hello";
printf("%s", emp.ch);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Compilation Error
main.c: In function ‘main’:
main.c:8:23: error: storage size of ‘emp’ isn’t known
struct Employ emp;