Programming in C IV

48 flashcards · Programming Languages · by Kamala Viswanathan

  1. What is a structure in C language? a) A structure is a collection of elements that can be of same datatype b) A structure is a collection of elements that can be of different datatype c) Elements of a structure are called members d) All of the these

    d) All of the these

  2. What is the size of a C structure? a) C structure is always 128 bytes b) Size of C structure is the total bytes of all elements of structure c) Size of C structure is the size of largest elements d) None of the above

    b) Size of C structure is the total bytes of all elements of structure

  3. Choose a correct statement about C structure? a) It is wrong to define an empty structure b) Member variables can be added to a structure even after its first definition c) There is no use of defining an empty structure d) None of the above

    b) Member variables can be added to a structure even after its first definition

  4. Choose a correct statement about C structure elements? a) Structure elements are stored on random free memory locations b) structure elements are stored in register memory locations c) structure elements are stored in contiguous memory locations d) None of the above

    c) structure elements are stored in contiguous memory locations

  5. A C structure or User defined datatype is also called ________. a) Derived data type b) Secondary data type c) Aggregate data type d) All the above

    d) All the above

  6. What are the uses of C Structures? a) structure is used to implement Linked Lists, Stack and Queue data structures B) Structures are used in Operating System functionality like Display and Input taking C) Structure are used to exchange information with peripherals of PC D) All the above

    D) All the above

  7. Choose a correct statement about C structures. a) A structure can contain same structure type member b) A structure size is limited by only physical memory of that PC c) You can define an unlimited number of members inside a structure d) All the above

    d) All the above

  8. 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

    d) none of the mentioned

  9. What will be the size of the following structure? a) 5 b) 11 c) 41 d) 44

    d) 44

  10. What will be the output of the following C code? a) Compile time error b) Nothing c) Junk values d) stst

    d) stst

  11. What will be the output of the following C code? a) 10 (Garbage Value) b) 0 10 c) 10 0 d) (Garbage Value) 10

    c) 10 0

  12. Which of the following operation is illegal in structures? a) Typecasting of structure b) Pointer to a variable of the same structure c) Dynamic allocation of memory for structure d) All of the mentioned

    a) Typecasting of structure

  13. What is the similarity between a structure, union and enumeration? A. All of them let you define new values B. All of them let you define new data types C. All of them let you define new pointers D. All of them let you define new structures

    B. All of them let you define new data types

  14. Union differs from structure in the following way A. All members are used at a time B. Only one member can be used at a time C. Union cannot have more members D. Union initialized all members as structure

    B. Only one member can be used at a time

  15. The size of the following union, where an int occupies 4 bytes of memory is A. 8 byte B. 4 byte C. 10 byte D. 18 byte

    C. 10 byte

  16. Members of a union are accessed as________________. A. union-name.member B. union-pointer->member C. Both a & b D. None of the mentioned

    C. Both a & b

  17. It is not possible to create an array of pointer to structures. A. TRUE B. FALSE C. May Be D. Can't Say

    B. FALSE Making sure of the length has nothing to do with whether you assign or copy. You cannot assign to an array in C, ever. The language doesn't allow it.

  18. Which of the following statement is True? A. User has to explicitly define the numeric value of enumerations B. User has a control over the size of enumeration variables. C. Enumeration can have an effect local to the block, if desired D. Enumerations have a global effect throughout the file.

    C. Enumeration can have an effect local to the block, if desired User has a control over the size of enumeration variable

  19. Size of union is size of the longest element in the union. A. Yes B. No C. May Be D. Can't Say

    A. Yes Max size of the union is the size of the largest data type or the memory taken by largest member.

  20. Local variables are stored in an area called ___________ a) Heap b) Permanent storage area c) Free memory d) Stack

    d) Stack

  21. The size of both stack and heap remains the same during run time. a) True b) False

    b) False

  22. Choose the statement which is incorrect with respect to dynamic memory allocation. a) Memory is allocated in a less structured area of memory, known as heap b) Used for unpredictable memory requirements c) Execution of the program is faster than that of static memory allocation d) Allocated memory can be changed during the run time of the program based on the requirement of the program

    c) Execution of the program is faster than that of static memory allocation Execution of the program using dynamic memory allocation is slower than that using static memory allocation. This is because in dynamic memory allocation, the memory has to be allocated during run time. This slows down the execution of the program.

  23. Which of the following header files must necessarily be included to use dynamic memory allocation functions? a) stdlib.h b) stdio.h c) memory.h d) dos.h

    a) stdlib.h stdlib.h is a header file which stands for the standard library. It consists of the declaration for dynamic memory allocation functions such as malloc(), calloc(), realloc() and free.

  24. The type of linked list in which the node does not contain any pointer or reference to the previous node is _____________ a) Circularly singly linked list b) Singly linked list c) Circular doubly linked list d) Doubly linked list

    b) Singly linked list A singly linked list is one in which each node has two fields, namely data field and pointer field. Data field stores the data and the pointer field points to the address of the next node.

  25. Which of the following is an example for non linear data type? a) Tree b) Array c) Linked list d) Queue

    a) Tree A data structure is said to be linear if its elements form a sequence or a linear list. For example array, linked list, queue, stack etc. Elements in a non linear data structure do not form a sequence. For example Trees, graphs etc.

  26. The advantage of using linked lists over arrays is that ________ a) Linked list is an example of linear data structure b) Insertion and deletion of an element can be done at any position in a linked list c) Linked list can be used to store a collection of homogenous and heterogeneous data types d) The size of a linked list is fixed

    b) Insertion and deletion of an element can be done at any position in a linked list Insertion and deletion in a linked list can be done at any position. On the other hand, in an array, to insert an element at a specific position, the rest of the elements have to be moved one position to the left and to delete an element, all the elements after the deleted element have to be moved one position to the right.

  27. What is the output if it is executed on a 32 bit processor? void main() { int *p; p = (int *)malloc(20); printf("%d", sizeof(p)); } (a) 2 (b) 4 (c) 8 (d) Garbage value

    (b) 4

  28. What is correct about calloc() function? (a) Allocates the space for elements of an array. (b) Initializes the elements to zero. (c) If space is insufficient returns a NULL pointer. (d) All of these

    (d) All of these

  29. When the pointer is NULL, then the function realloc is equivalent to the function ________ (a) malloc() (b) calloc() (c) free() (d) alloc()

    (a) malloc()

  30. If malloc() and calloc() are not type casted, the default return type is _____ (a) void* (b) void** (c) int* (d) char*

    (a) void*

  31. Which of the following functions allocates multiple blocks of memory, each block of the same size? (a) malloc() (b) realloc() (c) calloc() (d) free()

    (c) calloc()

  32. What is the output? void main() { char *p = calloc(100, 1); p = "welcome"; printf("%s", p); } (a) Address of p (b) welcome (c) Garbage value (d) Error

    (b) welcome

  33. What is the output? void main() { int *ptr; ptr = (int *)calloc(1,sizeof(int)); *ptr = 10; printf("%d\n",*ptr); } (a) 0 (b) -1 (c) 10 (d) NULL

    (c) 10

  34. What is the output? void main() { int *ptr; ptr = (int *)calloc(1,sizeof(int)); printf("%d\n",*ptr); } (a) 0 (b) -1 (c) Error (d) Null

    (a) 0

  35. Longevity of a variable refers to a) The duration for which the variable retains a given value during the execution of a program. b) The portion of a program in which the variable may be visible. c) Internal linkage of a variable. d) External linkage of a variable.

    a) The duration for which the variable retains a given value

  36. Which is not a storage class? a) Auto b) Struct c) Typedef d) Static

    b) Struct

  37. How many storage classes in c? A. 2 B. 3 C. 4 D. 5

    C. 4

  38. externint s; int t; static int u; main() { } Which of s, t and u are available to a function present in another file? a) Only s b) S & u c) S, t, u d) None

    a) Only s

  39. Which of the following statement are correct? (i) The value stored in the CPU register can always be accessed faster than that stored in memory. (ii) A register storage class variable will always be stored in a CPU register. a) Only I is correct b) Only II is correct c) Both I & II are correct d) Both I & II are incorrect

    a) Only I is correct

  40. What is the output of the following program? #include<stdio.h> int main() { static int a = 3; printf(“%d”, a --); return 0; } a) 0 b) 1 c) 2 d) 3

    d) 3

  41. Which of the following statement are correct? (I) The maximum value a variable can hold depends upon its storage class. (II) By default all variables enjoy a static storage class. a) Only I is correct b) Only II is correct c) Both I & II are correct d) Both I & II are incorrect

    d) Both I & II are incorrect

  42. What will be the output of the following program? #include<stdio.h> void fun() { fun(); Return 0; } void fun() { auto int I = 1; register char a = ‘D’; static int p = 0; printf(“%d %d %ld”, I, a, p); } a) 1 D 0 b) 1 0 0 c) 0 D 1 d) 1 68 0

    d) 1 68 0

  43. What will be the output of the following program? #include <stdio.h> static int y = 1; int main() { static int z; printf(“%d %d”, y, z); return 0; } a) Garbage value b) 0 0 c) 1 0 d) 1 1

    c) 1 0

  44. What will be the storage class of variable I in the code written below? #include<stdio.h> int main() { int I = 10; printf(“%d”, i); return 0; } a) Automatic storage class b) Extern storage class c) Static storage class d) Register storage class

    a) Automatic storage class

  45. What will be the output of the following code? static int I = 5; int main() { int sum = 0 do { sum + = (1/I); }while(0 < I --); printf(“sum of the series is %d”, sum); return 0; } a) It will print the sum of the series 1/5+1/4+…+1/1. b) It will produce a compilation error. c) It will produce a run time error. d) None.

    c) It will produce a run time error.

  46. What is the scope of extern class specifier? A. Within block B. Within Program C. Global Multiple files D. None of the above

    C. Global Multiple files Global Multiple files is the scope of extern class specifier.

  47. In case of a conflict between the names of a local and global variable what happens? a) The global variable is given a priority. b) The local variable is given a priority. c) Which one will get a priority depends upon which one is defined first. d) The compiler reports an error.

    b) The local variable is given a priority.

  48. What will be the output of the following program? #include<stdio.h> int main() { static unsigned int a = 23; register unsigned char c = ‘R’; auto long unsigned q = 345L; static long signed p = 345L; printf(“a = %u c = %c”, a ,c); printf(“\nq = %ld p = %ld”, q, p); return 0; } a) a=23 c=R q = 345 p = 345 b) A=23 c=R 0 0 c) Garbage value d) A=23 c=R q = 345 p = 345

    a) a=23 c=R q = 345 p = 345