Typedef
- Which of the given option is the correct method for initialization?
typedef char *string;
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
*string p = ‘A’;
- Which option should be selected to work the following C expression?
string s = "WELCOME";
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
typedef char *string;
- Which is the correct syntax to use typedef for struct?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Option A, B and C is correct syntax to use typedef for struct.
- What will be the output of the following C code?
#include <stdio.h>
typedef struct MM
{
int n1, n2;
}mm;
int main()
{
struct MM m = {22, 44};
mm k = m;
printf("%d\n", k.n1);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
22
- What will be the output of the following C code?
#include <stdio.h>
typedef struct NN
{
int n, m;
}s = {11, 22};
int main()
{
NN nn = s;
printf("%d\n", nn.n);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
Compilation Error
main.c:5:5: error: typedef ‘s’ is initialized (use __typeof__ instead)
}s = {11, 22};
^
main.c: In function ‘main’:
main.c:8:9: error: unknown type name ‘NN’; use ‘struct’ keyword to refer to the type
NN nn = s;
^~
struct
main.c:8:17: error: expected expression before ‘s’
NN nn = s;
^
main.c:9:26: error: request for member ‘n’ in something not a structure or union
printf("%d\n", nn.n);