C Programming – Typedefs

C Programming - Typedefs

Question 1
What is the output of this C code?
    #include 
    typedef struct student
    {
    char *a;
    }stu;
    void main()
    {
    struct stu s;
    s.a = "hi";
    printf("%s", s.a);
    }
A
Compile time error
B
Varies
C
hi
D
h
Question 2
What is the output of this C code?
    #include 
    typedef struct student
    {
    char *a;
    }stu;
    void main()
    {
    struct student s;
    s.a = "hey";
    printf("%s", s.a);
    }
A
Compile time error
B
Varies
C
he
D
hey
Question 3
What is the output of this C code?
    #include 
    typedef int integer;
    int main()
    {
    int i = 10, *ptr;
    float f = 20;
    integer j = i;
    ptr = &j;
    printf("%d\n", *ptr);
    return 0;
    }
A
Compile time error
B
Undefined behaviour
C
Depends on the standard
D
10
Question 4
What is the output of this C code?
    #include 
    int (*(x()))[2];
    typedef int (*(*ptr)())[2] ptrfoo;
    int main()
    {
    ptrfoo ptr1;
    ptr1 = x;
    ptr1();
    return 0;
    }
    int (*(x()))[2]
    {
    int (*ary)[2] = malloc(sizeof*ary);
    return &ary;
    }
A
Compile time error
B
Nothing
C
Undefined behaviour
D
Depends on the standard
Question 5
What is the output of this C code?
    #include 
    int *(*(x()))[2];
    typedef int **(*ptrfoo)())[2];
    int main()
    {
    ptrfoo ptr1;
    ptr1 = x;
    ptr1();
    return 0;
    }
    int *(*(x()))[2]
    {
    int (*ary)[2] = malloc(sizeof * ary);
    return &ary;
    }
A
Compile time error
B
Nothing
C
Undefined behaviour
D
Depends on the standard
Question 6
What is the output of this C code?
    #include 
    typedef struct p
    {
    int x, y;
    };
    int main()
    {
    p k1 = {1, 2};
    printf("%d\n", k1.x);
    }
A
Compile time error
B
1
C
0
D
Depends on the standard
Question 7
What is the output of this C code?
    #include 
    typedef struct p
    {
    int x, y;
    }k = {1, 2};
    int main()
    {
    p k1 = k;
    printf("%d\n", k1.x);
    }
A
Compile time error
B
1
C
0
D
Depends on the standard
Question 8
What is the output of this C code?
    #include 
    typedef struct p
    {
    int x, y;
    }k;
    int main()
    {
    struct p p = {1, 2};
    k k1 = p;
    printf("%d\n", k1.x);
    }
A
Compile time error
B
1
C
0
D
Depends on the standard
Question 9
The correct syntax to use typedef for struct is.
A
typedef struct temp { int a; }TEMP;
B
typedef struct { int a; }TEMP;
C
struct temp { int a; }; typedef struct temp TEMP;
D
All of the mentioned
Question 10
For the following expression to work, which option should be selected.    string p = “HELLO”;
A
typedef char [] string;
B
typedef char *string;
C
Both (a) and (b)
D
Such expression cannot be generated in C
Question 11
 Which of the given option is the correct method for initialization?     typedef char *string;
A
*string *p = “Hello”;
B
string p = “Hello”;
C
*string p = ‘A’;
D
Not more than one space should be given when using typedef
Question 12
Which of the following is FALSE about typedef?
A
typedef follow scope rules
B
typedef defined substitutes can be redefined again. (Eg: typedef char a; typedef int a;)
C
You cannot typedef a typedef with other term.
D
All of the mentioned
Question 13
 typedef which of the following may create problem in the program
A
;
B
printf/scanf
C
Arithmetic operators
D
All of the mentioned
Question 14
typedef int (*PFI)(char *, char *)creates
A
type PFI, for pointer to function (of two char * arguments) returning int
B
Error
C
type PFI, function (of two char * arguments) returning int
D
type PFI, for pointer
Question 15
 typedef declaration
A
Does not create a new type
B
It merely adds a new name for some existing type.
C
Both a & b
D
None of the mentioned
Question 16
What is the output of this C code?
    #include 
    typedef struct student
    {
    char *a;
    }stu;
    void main()
    {
    stu s;
    s.a = "hi";
    printf("%s", s.a);
    }s
A
Compile time error
B
Varies
C
hi
D
h


Check Your Answers:

  1. A
  2. D
  3. D
  4. A
  5. B
  6. A
  7. A
  8. B
  9. D
10. B
11. B
12. B
13. D
14. A
15. C
16. A
SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment