C LANGUAGE MULTIPLE CHOICE QUESTION

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
The Preprocessor Underlying C Language Features Copyright © 2012 by Yong-Gu Lee
Kernighan/Ritchie: Kelley/Pohl:
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Computer Science 210 Computer Organization Introduction to C.
1 Further C  Multiple source code file projects  Structs  The preprocessor  Pointers.
1 Homework HW6 due class 22 K&R 6.6 K&R 5.7 – 5.9 (skipped earlier) Finishing up K&R Chapter 6.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
6. More on Pointers 14 th September IIT Kanpur C Course, Programming club, Fall
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
Homework Finishing up K&R Chapter 6 today Also, K&R 5.7 – 5.9 (skipped earlier)
What we will cover A crash course in the basics of C “Teach yourself C in 21 days”
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
1 MT258 Computer Programming and Problem Solving Tutorial 03.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
C is a high level language (HLL)
1 Structures & Unions. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc)
Windows Programming Lecture 03. Pointers and Arrays.
Arrays and Pointers (part 1) CSE 2031 Fall July 2016.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
CSC 215 Pointers and Arrays. Pointers C provides two unary operators, & and *, for manipulating data using pointers The operator &, when applied to a.
Numbers in ‘C’ Two general categories: Integers Floats
Ex-1 #include <stdio.h> struct sample { int a=0; char b='A';
CSC215 Lecture Advanced Pointers.
CS1010 Programming Methodology
CS1010 Programming Methodology
User-Written Functions
Chapter 8 Arrays, Strings and Pointers
Computer Science 210 Computer Organization
C Primer.
CSC215 Lecture Advanced Pointers.
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
UNIT 5 C Pointers.
ICS103 Programming in C Lecture 3: Introduction to C (2)
INC 161 , CPE 100 Computer Programming
C Basics.
Module 2 Arrays and strings – example programs.
Programmazione I a.a. 2017/2018.
POINTERS.
Programmazione I a.a. 2017/2018.
Lecture 6 C++ Programming
11/10/2018.
14th September IIT Kanpur
Computer Science 210 Computer Organization
Lecture 9 Structure 1. Concepts of structure Pointers of structures
Arrays, For loop While loop Do while loop
Pointers Department of Computer Science-BGU יום רביעי 21 נובמבר 2018.
CS 240 – Lecture 18 Command-line Arguments, Typedef, Union, Bit Fields, Pointers to Functions.
Pointers  Week 10.
Pointers, Dynamic Data, and Reference Types
Lecture 18 Arrays and Pointer Arithmetic
Programming in C Pointer Basics.
Pointers.
Govt. Polytechnic,Dhangar
Outline Defining and using Pointers Operations on pointers
Programming in C Pointer Basics.
C Programming Getting started Variables Basic C operators Conditionals
WEEK-2.
Arrays.
Chapter 9: Pointers and String
Lecture 14: Problems with Lots of Similar Data
Programming in C Pointer Basics.
Arrays and Pointers CSE 2031 Fall May 2019.
Introduction to C Programming
Arrays and Pointers CSE 2031 Fall July 2019.
15213 C Primer 17 September 2002.
Presentation transcript:

C LANGUAGE MULTIPLE CHOICE QUESTION

Check your Knowledge Press to Start www.prolearninghub.com

1. Which of the following return-type cannot be used for a function in C? char * struct void None of the mentioned www.prolearninghub.com

2. Which of the following is not possible under any scenario? (*s1).number = 10; None of the mentioned www.prolearninghub.com

3. Which of the following operation is illegal in structures? Typecasting of structure Pointer to a variable of same structure Dynamic allocation of memory for structure All of the mentioned www.prolearninghub.com

4. Presence of code like “s.t.b = 10” indicate. Syntax Error Structure double data type An ordinary variable name www.prolearninghub.com

5. The output of the code below is #include <stdio 5. The output of the code below is #include <stdio.h> struct student{ char *name; }; struct student fun(void){ struct student s; s.name = "alan"; return s;} void main(){ struct student m = fun(); s.name = "turing"; printf("%s", m.name);} Alan Compile time error Turing Nothing www.prolearninghub.com

depends on the standard 6. What is the output of this C code? #include <stdio.h> struct point { int x; int y; }; int main() { struct point p = {1}; struct point p1 = {1}; if(p == p1) printf("equal\n"); else printf("not equal\n"); } Compile time error Equal depends on the standard not equal www.prolearninghub.com

7. What is the output of this C code. #include <stdio 7. What is the output of this C code? #include <stdio.h> struct point { in t x; int y; }; struct notpoint { int x; int y; }; struct point foo(); int main() { struct point p = {1}; struct notpoint p1 = {2, 3}; p1 = foo(); printf("%d\n", p1.x); } struct point foo() { struct point temp = {1, 2}; return temp; } compile time error Undefined behavior 1 2 www.prolearninghub.com

8. The correct syntax to access the member of the ith structure in the array of structures is?     Assuming: struct temp     {         int b;     }s[50]; s.b.[i]; s.[i].b; s.b[i]; s[i].b; www.prolearninghub.com

9. Comment on the output of this C code. #include <stdio 9. Comment on the output of this C code? #include <stdio.h> struct temp { int a; int b; int c; }; main() { struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; } No Compile time error, generates an array of structure of size 3 Compile time error, illegal assignment to members of structure No Compile time error, generates an array of structure of size 9 Compile time error, illegal declaration of a multidimensional array www.prolearninghub.com

10. Which of the following uses structure? Array of structures Linked Lists All of the mentioned Binary Tree www.prolearninghub.com

11. What is the correct syntax to declare a function foo() which receives an array of structure in function? void foo(struct *var); void foo(struct *var[]); void foo(struct var); None of the mentioned www.prolearninghub.com

Can’t be estimated due to ambiguous initialization of array 12. What is the output of this C code? (Assuming size of int be 4) #include <stdio.h> struct temp { int a; int b; int c; } p[] = {0}; main() { printf("%d", sizeof(p)); } 4 12 16 Can’t be estimated due to ambiguous initialization of array www.prolearninghub.com

13. What is the output of this C code. #include <stdio 13. What is the output of this C code? #include <stdio.h> struct student { char *name; }; struct student s[2]; void main() { s[0].name = "alan"; s[1] = s[0]; printf("%s%s", s[0].name, s[1].name); s[1].name = "turing"; printf("%s%s", s[0].name, s[1].name); } alan alan alan turing alan alan turing turing alan turing alan turing Run time error www.prolearninghub.com

14. Which of the following are incorrect syntax for pointer to structure? (Assuming struct temp{int b;}*my_struct;) *my_struct.b = 10; (*my_struct).b = 10; my_struct->b = 10; Both (a) and (b) www.prolearninghub.com

15. Which of the following is an incorrect syntax to pass by reference a member of a structure in a function? func(&s.a); func(&(s).a); func(&(s.a)); None of the mentioned www.prolearninghub.com

16. Which of the following structure declaration doesn’t require pass-by-reference? struct{int a;}s;     main(){} struct temp{int a;};     main(){         struct temp s;     } struct temp{int a;};     main(){}     struct temp s; None of the mentioned www.prolearninghub.com

17. For the following function call which option is not possible 17. For the following function call which option is not possible?     func(&s.a); //where s is a variable of type struct and a is the member of the struct A) Compiler can access entire structure from the function. C) Individual member’s address can be displayed in structure B) Individual member can be passed by reference in a function. Both (b) and (c). www.prolearninghub.com

Output varies with machine 18. Comment on the output of this C code? #include <stdio.h> struct temp { int a; } s; void change(struct temp); main() { s.a = 10; change(s); printf("%d\n", s.a); } void change(struct temp s) { s.a = 1; } Output will be 1 Output will be 10 Output varies with machine Compile time error www.prolearninghub.com

19. What is the output of this C code. #include <stdio 19. What is the output of this C code? #include <stdio.h> struct p { int x; int y; }; int main() { struct p p1[] = {1, 92, 3, 94, 5, 96}; struct p *ptr1 = p1; int x = (sizeof(p1) / 5); if (x == 3) printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x); else printf("false\n"); } Compile time error False Undefined behavior 1 5 www.prolearninghub.com

20. Size of a union is determined by size of the. First member in the union Last member in the union Biggest member in the union Sum of the sizes of all members www.prolearninghub.com

Such declaration are illegal 21. Comment on the following union declaration? #include <stdio.h> union temp { int a; float b; char c; };   union temp s = {1,2.5,’A’}; //REF LINE Which member of the union will be active after REF LINE? A B C Such declaration are illegal www.prolearninghub.com

22. What would be the size of the following union declaration 22.What would be the size of the following union declaration? #include <stdio.h> union uTemp { double a; int b[10]; char c; } u;     (Assuming size of double = 8, size of int = 4, size of char = 1) 4 8 40 80 www.prolearninghub.com

23. What type of data is holded by variable u int this C code 23. What type of data is holded by variable u int this C code? #include <stdio.h> union u_tag { int ival; float fval; char *sval; } u; Will be large enough to hold the largest of the three types; Will be large enough to hold the smallest of the three types; Will be large enough to hold the all of the three types; None of the mentioned www.prolearninghub.com

24. Members of a union are accessed as________________. A) union-name.member B) union-pointer->member Both A & B None of the mentioned www.prolearninghub.com

You cannot have union inside structure 25. What is the output of this C code? #include <stdio.h> struct { char *name; union{ char *sval;} u;} symtab[10]; the first character of the string sval by either of A) *symtab[i].u.sval B) symtab[i].u.sval[0] You cannot have union inside structure Both a & b www.prolearninghub.com

26. What is the output of this C code(size of int and float is 4) 26. What is the output of this C code(size of int and float is 4)? #include <stdio.h> union { int ival; float fval; } u; void main() { printf("%d", sizeof(u)); } 16 8 4 32 www.prolearninghub.com

27. What is the output of this C code. #include <stdio 27. What is the output of this C code? #include <stdio.h> union stu { int ival; float fval; }; void main() { union stu r; r.ival = 5; printf("%d", r.ival); } 9 16 5 Compile time error www.prolearninghub.com

28. What is the output of this C code. #include <stdio 28. What is the output of this C code? #include <stdio.h> union { int x; char y; }p; int main() { p.x = 10; printf("%d\n", sizeof(p)); } Compile time error Sizeof(int) + sizeof(char) Depends on the compiler Sizeof(int) www.prolearninghub.com

29. What is the output of this C code. #include <stdio 29. What is the output of this C code? #include <stdio.h> union { int x; char y; }p; int main() { p.x = 10; printf("%d\n", sizeof(p)); } Compile time error Sizeof(int) + sizeof(char) Depends on the compiler Sizeof(int) www.prolearninghub.com

Depends on the compiler 30. What is the output of this C code? #include <stdio.h> union p { int x; char y; }; int main() { union p p, b; p.y = 60; b.x = 12; printf("%d\n", p.y); } Compile time error Depends on the compiler 60 Undefined behaviour www.prolearninghub.com

31. What is the output of this C code. #include <stdio 31. What is the output of this C code? #include <stdio.h> union p { int x; char y; }k = {1, 97}; int main() { printf("%d\n", k.y); } Compile time error 97 A 1 www.prolearninghub.com

Depends on the standard 32. What is the output of this C code? #include <stdio.h> union p { int x; char y; }k = {.y = 97}; int main() { printf("%d\n", k.y); } Compile time error 97 A Depends on the standard www.prolearninghub.com

Implementation dependent 33. What is the output of this C code? #include <stdio.h> union p { int x; float y; }; int main() { union p p, b; p.x = 10; printf("%f\n", p.y); } Compile time error Implementation dependent 10.000000 0.000000 www.prolearninghub.com

34. Which of the following share a similarity in syntax. 1. Union 2 34. Which of the following share a similarity in syntax? 1. Union 2. Structure 3. Arrays 4. Pointers 2 and 4 3 and 4 1 and 3 1 and 2 www.prolearninghub.com

35. What is the output of this C code. #include <stdio 35. What is the output of this C code? #include <stdio.h> union utemp { int a; double b; char c; }u; int main() { u.c = 'A'; u.a = 1; printf("%d", sizeof(u)); }     The output will be: (Assuming size of char = 1, int = 4, double = 8) 1 4 6 8 www.prolearninghub.com

36. The address operator &, cannot act on R-value Arithmetic expressions R-value and Arithmetic expressions Local variable www.prolearninghub.com

37. C preprocessor: Takes care of conditional compilation Takes care of macros Takes care of include files All of them www.prolearninghub.com

38. A preprocessor command need not start on a new line Need not start on the first column Has # as the first character Comes before the first executable statement www.prolearninghub.com

39. What will be the output of the program. #include<stdio 39. What will be the output of the program? #include<stdio.h> #define int char void main() { int i = 65; printf("sizeof(i)=%d", sizeof(i)); } sizeof(i)=2 sizeof(i)=1 Compiler Error None of These www.prolearninghub.com

40. What will be the output of the following program? #include<stdio.h> #define square(x) x*x void main() { int i; i = 64/square(4); printf("%d", i); } 4 64 16 None of these www.prolearninghub.com

41. What will be the output of the program code. #include<stdio 41. What will be the output of the program code? #include<stdio.h> #define a 10 void main() { #define a 50 printf("%d", a); } 50 10 Compiler error None of these www.prolearninghub.com

42. Find the output of the following program 42. Find the output of the following program. void main() { printf("%d, %d", sizeof(int *), sizeof(int **)); } 2, 0 2, 2 0, 2 2,4 www.prolearninghub.com

43. Find the output of the following program. void main() { int i=10; /* assume address of i is 0x1234ABCD */ int *ip=&i; int **ipp=&&i; printf("%x,%x,%x", &i, ip, *ipp); } 0x1234ABCD, 0x1234ABCD, 10 0x1234ABCD, 0x1234ABCD, 0x1234ABCD 0x1234ABCD, 10, 10 Syntax error www.prolearninghub.com

44. What is the base data type of a pointer variable by which the memory would be allocated to it? Float No data type Unassigned int www.prolearninghub.com

45. The operator > and < are meaningful when used with pointers, if The pointers point to structure of similar data type. The pointers point to elements of the same array. None of these www.prolearninghub.com

46. The declaration int (*p) [5]; means p is one dimensional array of size 5, of pointers to integers. p is a pointer to a 5 elements integer array The same as int *p[ None of these www.prolearninghub.com

47. #define PI 3.141 Its float Its double There is no type associated with PI, as it’s just a text substitution Syntax error, semi colon is missing with the definition of PI www.prolearninghub.com

48. In DOS, What is the purpose of the function  randomize() in Turbo C? Displays a random number generator with a random value based on time Displays a random number Displays a random number generator in the specified range. Invalid function www.prolearninghub.com

49. Predict the data type of the following mathematical operation. 2 int long float double www.prolearninghub.com

50. Which of the following % operation is invalid? 2 % 4; 2 % 4f; 2 % 4l; None www.prolearninghub.com

The Results