C Programming Questions and Answers on Structures and Functions for Freshers

1. What is the output of this C code?
  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     struct student s;
  7.     struct student fun(void)
  8.     {
  9.         s.name = "newton";
  10.         printf("%s\n", s.name);
  11.         s.name = "alan";
  12.         return s;
  13.     }
  14.     void main()
  15.     {
  16.         struct student m = fun();
  17.         printf("%s\n", m.name);
  18.         m.name = "turing";
  19.         printf("%s\n", s.name);
  20.     }
a) newton alan alan
b) alan newton alan
c) alan alan newton
d) Compile time error
Answer: a
2. What is the output of this C code?
  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     void main()
  7.     {
  8.         struct student s, m;
  9.         s.name = "st";
  10.         m = s;
  11.         printf("%s%s", s.name, m.name);
  12.     }
a) Compile time error
b) Nothing
c) Junk values
d) st st
Answer: d
3. Which of the following return-type cannot be used for a function in C?

a) char *
b) struct
c) void
d) none of the mentioned
Answer: d
4. What’s the output of the following code?
  1.     #include 
  2.     struct temp
  3.     {
  4.         int a;
  5.     } s;
  6.     void func(struct temp)
  7.     {
  8.         s.a = 10;
  9.         printf("%d\t", s.a); s
  10.     }
  11.     main()
  12.     {
  13.         func(s);
  14.         printf("%d\t", s.a);
  15.     }
a) 10 (Garbage Value)
b) 0 10
c) 10 0
d) (Garbage Value) 10
Answer: c
5. Which of the following is not possible under any scenario?

a) s1 = &s2;
b) s1 = s2;
c) (*s1).number = 10;
d) None of the mentioned
Answer: d
6. Which of the following operation is illegal in structures?

a) Typecasting of structure
b) Pointer to a variable of same structure
c) Dynamic allocation of memory for structure
d) All of the mentioned
Answer: a
7. Presence of code like “s.t.b = 10” indicate.

a) Syntax Error
b) structure
c) double data type
d) An ordinary variable name
Answer: b
8. The output of the code below is
  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     struct student fun(void)
  7.     {
  8.         struct student s;
  9.         s.name = "alan";
  10.         return s;
  11.     }
  12.     void main()
  13.     {
  14.         struct student m = fun();
  15.         s.name = "turing";
  16.         printf("%s", m.name);
  17.     }
a) alan
b) Turing
c) Compile time error
d) Nothing
Answer: c
9. What is the output of this C code?
  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     int main()
  8.     {
  9.         struct point p = {1};
  10.         struct point p1 = {1};
  11.         if(p == p1)
  12.             printf("equal\n");
  13.         else
  14.             printf("not equal\n");
  15.     }
a) Compile time error
b) equal
c) depends on the standard
d) not equal
Answer: a
10. What is the output of this C code?
  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     struct notpoint
  8.     {
  9.         int x;
  10.         int y;
  11.     };
  12.     struct point foo();
  13.     int main()
  14.     {
  15.         struct point p = {1};
  16.         struct notpoint p1 = {2, 3};
  17.         p1 = foo();
  18.         printf("%d\n", p1.x);
  19.     }
  20.     struct point foo()
  21.     {
  22.         struct point temp = {1, 2};
  23.         return temp;
  24.     }
a) Compile time error
b) 1
c) 2
d) Undefined behaviour
Answer: a
11. What is the output of this C code?
  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     struct notpoint
  8.     {
  9.         int x;
  10.         int y;
  11.     };
  12.     int main()
  13.     {
  14.         struct point p = {1};
  15.         struct notpoint p1 = p;
  16.         printf("%d\n", p1.x);
  17.     }
a) Compile time error
b) 1
c) 0
d) Undefined
Answer: a
12. What is the output of this C code?
  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     struct notpoint
  8.     {
  9.         int x;
  10.         int y;
  11.     };
  12.     void foo(struct point);
  13.     int main()
  14.     {
  15.         struct notpoint p1 = {1, 2};
  16.         foo(p1);
  17.     }
  18.     void foo(struct point p)
  19.     {
  20.         printf("%d\n", p.x);
  21.     }
a) Compile time error
b) 1
c) 0
d) Undefined
Answer: a
13. What is the output of this C code?
  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1 = {1, 2};
  11.         foo(&p1);
  12.     }
  13.     void foo(struct point *p)
  14.     {
  15.         printf("%d\n", *p.x++);
  16.     }
a) Compile time error
b) Segmentation fault/code crash
c) 2
d) 1
Answer: a
14. What is the output of this C code?
  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1 = {1, 2};
  11.         foo(&p1);
  12.     }
  13.     void foo(struct point *p)
  14.     {
  15.         printf("%d\n", *p->x++);
  16.     }
a) Compile time error
b) 1
c) Segmentation fault/code crash
d) 2
Answer: a
15. What is the output of this C code?
  1.     #include 
  2.     struct student fun(void)
  3.     {
  4.         struct student
  5.         {
  6.             char *name;
  7.         };
  8.         struct student s;
  9.         s.name = "alan";
  10.         return s;
  11.     }
  12.     void main()
  13.     {
  14.         struct student m = fun();
  15.         printf("%s", m.name);
  16.     }
a) Compile time error
b) alan
c) Nothing
d) Varies
Answer: a
16. What is the output of this C code?
  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     struct student fun(void)
  7.     {
  8.         struct student s;
  9.         s.name = "alan";
  10.         return s;
  11.     }
  12.     void main()
  13.     {
  14.         struct student m = fun();
  15.         printf("%s", m.name);
  16.     }
a) Nothing
b) alan
c) Run time error
d) Varies
Answer: b

Related

Computer Fundamentals Multiple choice Questions and Answers on Boolean Functions for Freshers

1. Boolean Function is of the form of ________ a) Truth valuesb) K=f(X,Y,X)c) Algebraic Expressiond) Truth Table Answer: a Explanation: The boolean function is of the form of algebraic expression...

Multiple choice Questions and Answers on Event-Driven SOA or SOA 2.0 of Cloud Computing for Freshers

1. What should be the message given by Web Service 3 to Web Service 2 in the following figure for execution in cooperative way ? a) Replyb) Invokec) Rejectd) None of the mentioned Answer: a Expla...

Multiple Choice Questions and Answers on Service Oriented Architecture of Cloud Computing for Freshers

1. Which of the following describes a message-passing taxonomy for a component-based architecture that provides services to clients upon demand ? a) SOAb) EBSc) GECd) All of the mentioned Answer: ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item