Your browser is no longer supported. Update it to get the best YouTube experience and our latest features. Learn more
6.What does the following C expression do?x = x & (x-1)(a) Sets all bits as 1(b) Makes x equals to 0(c) Turns of the rightmost set bit(d) Turns of the leftmost set bitSolution:Option (c)Explanation:The expression simply turns off the rightmost set bit. For example, if x = 14 (1110), it returns 12(1100). Related Textbook Solutions See more7.Consider the C function given below. Assume that the array listA contains n (> 0) elements,sorted in ascending order.int ProcessArray(int *listA, int x, int n){int i, j, k;i = 0;j = n-1;do{k = (i+j)/2;if (x≤listA[k])j = k-1;if (listA[k]≤x)i = k+1;}while (i≤j);if (listA[k] = = x)return(k);elsereturn -1;}Which one of the following statements about the function ProcessArray is CORRECT? Get answer to your question and much more 38.What is the output of following program?#include <stdio.h>void print(int n, int j){if (j≥n)return;if (n-j > 0 && n-j≥j)printf("%d %d\n", j, n-j); Get answer to your question and much more 9.Which of the following is correct recurrence for worst case of Binary Search? Get answer to your question and much more 410.Given a sorted array of integers, what can be the minimum worst case time complexity tofind ceiling of a number x in given array? Ceiling of an element x is the smallest element presentin array which is greater than or equal to x. Ceiling is not present if x is greater than themaximum element present in array. For example, if the given array is {12, 67, 90, 100, 300, 399}and x = 95, then output should be 100. (a) O (Log Log n)(b) O (n)(c) O (Log n)(d) O (Log n * Log n)Solution:Option (c)Explanation:We modify standard binary search to find ceiling. The time complexity T(n) can be written as:T(n)≤T(n/2) + O(1)Solution of above recurrence can be obtained by Master Method. It falls in case 2 of MasterMethod. Solution is O (Log n). Upload your study docs or become a Course Hero member to access this document Upload your study docs or become a Course Hero member to access this document End of preview. Want to read all 9 pages? Upload your study docs or become a Course Hero member to access this document
Here are 1000 MCQs on C Programming (Chapterwise). 1. Who is the father of C language? a) Steve Jobs b) James Gosling c) Dennis Ritchie d) Rasmus Lerdorf View Answer Answer: c Explanation: Dennis Ritchie is the father of C Programming Language. C programming language was developed in 1972 at American Telephone & Telegraph Bell Laboratories of USA. 2. Which of the following is not a valid C variable name? a) int number; b) float rate; c) int variable_count; d) int $main; View Answer Answer: d Explanation: Since only underscore and no other special character is allowed in a variable name, it results in an error. 3. All keywords in C are in ____________ a) LowerCase letters b) UpperCase letters c) CamelCase letters d) None of the mentioned View Answer Answer: a Explanation: None. 4. Which of the following is true for variable names in C? a) They can contain alphanumeric characters as well as special characters b) It is not an error to declare a variable to be one of the keywords(like goto, static) c) Variable names cannot start with a digit d) Variable can be of any length View Answer Answer: c 5. Which is valid C expression? a) int my_num = 100,000; b) int my_num = 100000; c) int my num = 1000; d) int $my_num = 10000; View Answer Answer: b Explanation: Space, comma and $ cannot be used in a variable name. 6. Which of the following cannot be a variable name in C? a) volatile b) true c) friend d) export View Answer Answer: a Explanation: volatile is C keyword. 7. What is short int in C programming? a) The basic data type of C b) Qualifier c) Short is the qualifier and int is the basic data type d) All of the mentioned View Answer Answer: c Explanation: None. 8. Which of the following declaration is not supported by C language? a) String str; b) char *str; c) float str = 3e2; d) Both String str; & float str = 3e2; View Answer Answer: a Explanation: It is legal in Java, but not in C language. 9. Which keyword is used to prevent any changes in the variable within a C program? a) immutable b) mutable c) const d) volatile View Answer Answer: c Explanation: const is a keyword constant in C program. 10. What is the result of logical or relational expression in C? a) True or False b) 0 or 1 c) 0 if an expression is false and any positive number if an expression is true d) None of the mentioned View Answer Answer: b 11. Which of the following typecasting is accepted by C language? a) Widening conversions b) Narrowing conversions c) Widening & Narrowing conversions d) None of the mentioned View Answer Answer: c 12. Where in C the order of precedence of operators do not exist? a) Within conditional statements, if, else b) Within while, do-while c) Within a macro definition d) None of the mentioned View Answer Answer: d 13. Which of the following is NOT possible with any 2 operators in C? a) Different precedence, same associativity b) Different precedence, different associativity c) Same precedence, different associativity d) All of the mentioned View Answer Answer: c 14. What is an example of iteration in C? a) for b) while c) do-while d) all of the mentioned View Answer Answer: d 15. Functions can return enumeration constants in C? a) true b) false c) depends on the compiler d) depends on the standard View Answer Answer: a 16. Functions in C Language are always _________ a) Internal b) External c) Both Internal and External d) External and Internal are not valid terms for functions View Answer Answer: b 17. Which of following is not accepted in C? a) static a = 10; //static as b) static int func (int); //parameter as static c) static static int a; //a static variable prefixed with static d) all of the mentioned View Answer Answer: c 18. Property which allows to produce different executable for different platforms in C is called? a) File inclusion b) Selective inclusion c) Conditional compilation d) Recursive macros View Answer Answer: c 19. What is #include <stdio.h>? a) Preprocessor directive b) Inclusion directive c) File inclusion directive d) None of the mentioned View Answer Answer: a 20. C preprocessors can have compiler specific features. a) True b) False c) Depends on the standard d) Depends on the platform View Answer Answer: a 21. Which of the following are C preprocessors? a) #ifdef b) #define c) #endif d) all of the mentioned View Answer Answer: d 22. The C-preprocessors are specified with _________ symbol. a) # b) $ c) ” ” d) & View Answer Answer: a 23. How is search done in #include and #include “somelibrary.h” according to C standard? a) When former is used, current directory is searched and when latter is used, standard directory is searched b) When former is used, standard directory is searched and when latter is used, current directory is searched c) When former is used, search is done in implementation defined manner and when latter is used, current directory is searched d) For both, search for ‘somelibrary’ is done in implementation-defined places View Answer Answer: d 24. How many number of pointer (*) does C have against a pointer variable declaration? a) 7 b) 127 c) 255 d) No limits View Answer Answer: d 25. Which of the following is not possible statically in C language? a) Jagged Array b) Rectangular Array c) Cuboidal Array d) Multidimensional Array View Answer Answer: a 26. 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 View Answer Answer: d 27. The standard header _______ is used for variable list arguments (…) in C. a) <stdio.h > b) <stdlib.h> c) <math.h> d) <stdarg.h> View Answer Answer: d 28. When a C program is started, O.S environment is responsible for opening file and providing pointer for that file? a) Standard input b) Standard output c) Standard error d) All of the mentioned View Answer Answer: d 29. In C language, FILE is of which data type? a) int b) char * c) struct d) None of the mentioned View Answer Answer: c 30. What is the sizeof(char) in a 32-bit C compiler? a) 1 bit b) 2 bits c) 1 Byte d) 2 Bytes View Answer Answer: c 31. Which of the following is not an operator in C? a) , b) sizeof() c) ~ d) None of the mentioned View Answer Answer: d 32. scanf() is a predefined function in______header file. a) stdlib. h b) ctype. h c) stdio. h d) stdarg. h View Answer Answer: c 33. What is meant by ‘a’ in the following C operation? fp = fopen("Random.txt", "a"); a) Attach b) Append c) Apprehend d) Add View Answer Answer: b 34. What will be the output of the following C code?
a) Compile time error b) Hello World! 34 c) Hello World! 1000 d) Hello World! followed by a junk value View Answer Answer: a Explanation: Since y is already defined, redefining it results in an error. Output: $ cc pgm2.c pgm2.c: In function ‘main’: pgm2.c:5: error: redefinition of ‘y’ pgm2.c:4: note: previous definition of ‘y’ was here 35. What will happen if the following C code is executed?
a) It will cause a compile-time error b) It will cause a run-time error c) It will run without any error and prints 3 d) It will experience infinite looping View Answer Answer: c Explanation: A C program can have same function name and same variable name. $ cc pgm3.c $ a.out 3 36. What will be the output of the following C code?
a) 128 b) -128 c) Depends on the compiler d) None of the mentioned View Answer Answer: b Explanation: signed char will be a negative number. Output: $ cc pgm2.c $ a.out -128 37. What will be the output of the following C code on a 64 bit machine?
a) 8 b) 5 c) 9 d) 4 View Answer Answer: d Explanation: Since the size of a union is the size of its maximum data type, here int is the largest data type. Hence the size of the union is 4. Output: $ cc pgm7.c $ a.out 4 38. What will be the output of the following C function?
a) 0 b) Compile time error c) 1 d) 8 View Answer Answer: d Explanation: m is an integer constant, hence it is compatible. Output: $ cc pgm5.c $ a.out 8 39. What will be the output of the following C code?
a) Error because function name cannot be preceded by const b) Sanfoundry.com c) Sanfoundry.com is printed infinite times d) Blank screen, no output View Answer Answer: b Explanation: None. Output: $ cc pgm13.c $ a.out Sanfoundry.com 40. Will the following C code compile without any error?
a) Yes b) No c) Depends on the C standard implemented by compilers d) Error View Answer Answer: c Explanation: Compilers implementing C90 do not allow this, but compilers implementing C99 allow it. Output: $ cc pgm4.c pgm4.c: In function ‘main’: pgm4.c:4: error: ‘for’ loop initial declarations are only allowed in C99 mode pgm4.c:4: note: use option -std=c99 or -std=gnu99 to compile your code 41. What will be the final value of x in the following C code?
a) 3.75 b) Depends on compiler c) 24 d) 3 View Answer Answer: c Explanation: None. 42. What will be the output of the following C code? (Initial values: x= 7, y = 8)
a) 7.000000, 7 b) Run time error c) 7.000000, junk d) Varies View Answer Answer: c Explanation: None. 43. What will be the output of the following C code considering the size of a short int is 2, char is 1 and int is 4 bytes?
a) 2, 1, 2 b) 2, 1, 1 c) 2, 1, 4 d) 2, 2, 8 View Answer Answer: c 44. What is the difference between the following 2 C codes?
a) No difference as space doesn’t make any difference, values of a, b, d are same in both the case b) Space does make a difference, values of a, b, d are different c) Program 1 has syntax error, program 2 is not d) Program 2 has syntax error, program 1 is not View Answer Answer: d Explanation: None. 45. What will be the output of the following C code snippet?
a) returns 1 b) returns 2 c) Varies d) Compile time error View Answer Answer: d Explanation: None. 46. What will be the value of the following assignment expression? (x = foo())!= 1 considering foo() returns 2a) 2 b) True c) 1 d) 0 View Answer Answer: a 47. What will be the output of the following C function?
a) 1 2 3 4 5 b) Segmentation fault c) Compilation error d) Undefined behaviour View Answer Answer: a Explanation: None. 48. What will be the final values of i and j in the following C code?
a) i value is 1 and j value is 1 b) i value is 0 and j value is 0 c) i value is 1 and j value is undefined d) i and j value are undefined View Answer Answer: c Explanation: None. 49. Comment on the following C statement. n = 1; printf("%d, %dn", 3*n, n++); a) Output will be 3, 2 b) Output will be 3, 1 c) Output will be 6, 1 d) Output is compiler dependent View Answer Answer: d 50. How many times i value is checked in the following C program?
a) 2 b) 3 c) 4 d) 1 View Answer Answer: c 51. What will be the output of the following C code?
a) In while loop 2 b) In while loop in while loop 3 c) In while loop 3 d) Infinite loop View Answer Answer: a 52. What will be the data type returned for the following C function?
a) char b) int c) double d) multiple type-casting in return is illegal View Answer Answer: b 53. What is the problem in the following C declarations? int func(int); double func(int); int func(float); a) A function with same name cannot have different signatures b) A function with same name cannot have different return types c) A function with same name cannot have different number of parameters d) All of the mentioned View Answer Answer: d 54. Which option should be selected to work the following C expression? a) typedef char [] string; b) typedef char *string; c) typedef char [] string; and typedef char *string; d) Such expression cannot be generated in C View Answer Answer: b 55. What is the meaning of the following C statement? printf(“%10s”, state);a) 10 spaces before the string state is printed b) Print empty spaces if the string state is less than 10 characters c) Print the last 10 characters of the string d) None of the mentioned View Answer Answer: b 56. What are the elements present in the array of the following C code? a) 5, 5, 5, 5, 5 b) 5, 0, 0, 0, 0 c) 5, (garbage), (garbage), (garbage), (garbage) d) (garbage), (garbage), (garbage), (garbage), 5 View Answer Answer: b 57. What will be the output of the following C function when EOF returns? int fputs(char *line, FILE *fp) a) ‘�’ character of array line is encountered b) ‘n’ character in array line is encountered c) ‘t’ character in array line is encountered d) When an error occurs View Answer Answer: d 58. Which part of the program address space is p stored in the following C code?
a) Code/text segment b) Data segment c) Bss segment d) Stack View Answer Answer: c 59. Which of the following sequences are unaccepted in C language? b) c) d) View Answer Answer: c 59. Comment on the output of following C code.
a) It will print a b) It will print 0 c) Compile time error d) Run time error View Answer Answer:d Output: $ cc pgm.c $ a.out Segmentation fault (core dumped) 60. What is the output of this C code?
a) True b) False View Answer Answer:b Output: $ cc pgm.c $ a.out False 61. What is the output of this C code?
a) abnfoundry C-Test b) Sanfoundry C-Test c) Compile time error d) Run time error View Answer Answer:d Output: $ cc pgm.c $ a.out Segmentation fault (core dumped) 62. What is the output of this C code?
a) True b) False View Answer Answer:a Output: $ cc pgm.c $ a.out False 63. What is the output of this C code?
a) True b) False c) No Output will be printed d) Run Time Error View Answer Answer:c Output: $ cc pgm.c $ a.out $ Our 1000+ MCQs focus on all topics of the C Programming subject, covering 100+ topics. This will help you to prepare for exams, contests, online tests, quizzes, viva-voce, interviews, and certifications. You can practice these MCQs chapter by chapter starting from the 1st chapter or you can jump to any chapter of your choice. You can also download the PDF of C Programming MCQs by applying below.
The section contains C MCQs on variable names, datatypes, constants, declarations, arithmetic operators, relational and logical operators, type conversions, bitwise operators, assignment operators, increment and decrement operators, conditional expressions, evaluation order and precedence.
The section contains C multiple choice questions and answers on standard input and output, formatted input and output, variable length argument, file access, error handling, line input and output, string operations, character class testing, ungetc, storage management, mathematical functions, random number generation, file operations, printf and scanf. If you would like to learn "C Programming" thoroughly, you should attempt to work on the complete set of 1000+ MCQs - multiple choice questions and answers mentioned above. It will immensely help anyone trying to crack an exam or an interview. Note: We are working on pdf download for C Programming MCQs and will publish the download link here. Fill this C Programming mcq pdf download request form for download notification. Wish you the best in your endeavor to learn and master C Programming!
Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses. |