Subjectnest.com
  • Home
  • About
  • Contact
  • Privacy Policy
    • Terms of Use
    • Cookie Privacy Policy
    • California Consumer Privacy Act (CCPA)
    • DMCA
  • Free Tools
Menu
  • Home
  • About
  • Contact
  • Privacy Policy
    • Terms of Use
    • Cookie Privacy Policy
    • California Consumer Privacy Act (CCPA)
    • DMCA
  • Free Tools

Marketing MCQs

SEO MCQs

Social Media Marketing MCQs

Content Marketing MCQs

Digital Marketing MCQs

Pay-Per-Click (PPC) MCQs

Email Marketing MCQs

Mobile Marketing MCQs

Online Marketing MCQs

YouTube Marketing MCQs

Conversion Rate Optimization MCQs

Exam Preparation MCQs

MDCAT Support & Movement MCQs

MDCAT Alcohols and Phenols MCQs

MDCAT Dawn of Modern Physics MCQs

CSS English MCQs

CSS Business Administration MCQs

CSS Anthropology MCQs

Nts Multiple Choice

MDCAT Variation & Genetics MCQs

MDCAT Aldehydes and Ketones MCQs

MDCAT Spectra MCQs

CSS Pakistan Affairs MCQs

CSS Town Planning & Urban Management MCQs

CSS Pashto MCQs

NTS English Preparation Mcqs

MDCAT Fundamentals of Chemistry MCQs

MDCAT Acids MCQs

MDACT Nuclear Physics MCQs

CSS Current Affairs MCQs

CSS Computer Science MCQs

CSS Persian MCQs

NTS Physics Preparation Mcqs

MDCAT Gases MCQs

MDCAT Molecules MCQs

PPSC General Knowledge MCQs

CSS Islamic Studies MCQs

CSS International Relations MCQs

CSS Punjabi MCQs

MDCAT IMPORTANT MCQs

MDCAT Liquid MCQs

PPSC Solved MCQs Part 1

PPSC Current Affairs MCQs

CSS Comparative Study MCQs

CSS Political Science MCQs

CSS Constitutional Law MCQs

MDCAT Kingdom Animalia MCQs

MDCAT Solid MCQs

MDCAT Force and Motion MCQs

PPSC Pakistan Studies MCQs

CSS Geology MCQs

CSS Gender Studies MCQs

CSS International Law MCQs

Nervous & Chemical Coordination MCQs

MDCAT Chemical Equilibrium MCQs

MDCAT Work and Energy MCQs

PPSC Islamic Studies MCQs

CSS Statistics MCQs

CSS Environmental Science MCQs

CSS Muslim Law & Jurisprudence MCQs

MDCAT Cell Structure & Function MCQs

MDCAT Thermochemistry MCQs

MDCAT Rotational and Circular Motion MCQs

PPSC Geography MCQs

CSS History of Pakistan and India MCQs

CSS Agriculture and Forestry MCQs

CSS Mercantile Law MCQs

MDCAT Biological Molecules (Biomolecules) MCQs

MDCAT Electrochemistry MCQs

MDCAT Waves MCQs

PPSC English MCQs

CSS Accountancy & Auditing MCQs

CSS Botany MCQs

CSS Criminology MCQs

MDCAT Bioenergetics MCQs

MDCAT English MCQs

MDCAT Thermodynamics MCQs

PPSC Urdu MCQs

CSS Economics MCQs

CSS Zoology MCQs

CSS Philosophy MCQs

MDCAT Biodiversity (Variety of Life ) MCQs

MDCAT Chemical Bonding MCQs

MDCAT Electrostatics MCQs

PPSC Everyday Science MCQs

CSS Islamic History & Culture MCQs

CSS English Literature MCQs

CSS Arabic MCQs

MDCAT Enzymes MCQs

MDCAT S and P Block Elements MCQs

MDCAT Current Electricity MCQs

PPSC Computer MCQs

CSS British History MCQs

CSS Law MCQs

MDCAT Evolution MCQs

MDACT Transition Elements MCQs

MDCAT Electromagnetism MCQs

PPSC Mathematics MCQs

CSS European History MCQs

CSS Journalism & Mass Communication MCQs

MDCAT Nutrition & Gaseous Exchange MCQs

MDCAT Organic Chemistry MCQs

MDCAT Electromagnetic Induction MCQs

CSS Physics MCQs

CSS History of the USA MCQs

CSS Psychology MCQs

MDCAT Prokaryotes MCQs

MDCAT Hydrocarbons MCQs

MDCAT Electronics MCQs

CSS Chemistry MCQs

CSS Public Administration MCQs

CSS Geography MCQs

C Programming Mcqs

This comprehensive set of C Programming MCQs is designed to cover all essential topics required for success in exams related to programming and software development using the C language. Focused on key subjects such as data types, control structures, functions, pointers, memory management, and file handling, these MCQs are crafted to help students build a strong foundation in C programming concepts and techniques.

Who should practice C Programming MCQs?

  • Students preparing for courses in computer science, software engineering, or IT that cover the C programming language.
  • Individuals aiming to strengthen their understanding of C programming fundamentals, including arrays, structures, functions, and dynamic memory allocation.
  • Candidates preparing for competitive exams or certifications that assess knowledge of C language programming and problem-solving.
  • Learners interested in mastering advanced topics such as recursion, pointers, file I/O, and bitwise operations in C.
  • Professionals focused on improving their skills in low-level programming, embedded systems, or systems programming using C.
  • Suitable for all aspirants seeking to enhance their knowledge and performance in C programming for academic or professional success.

 

1. Which of the following statements can be interpreted in multiple ways?

a) Vagueness
b) Comments
c) Contradictions
d) Ambiguities

View Answer
D

Explanation: Ambiguities refer to statements or expressions that can be interpreted in multiple ways, causing confusion or multiple possible meanings.

 

2. Which of the following is the correct syntax for a for loop in C?

a) for (int i = 0; i < 10; i++) { /* code */ }
b) for int i = 0; i < 10; i++ { /* code */ }
c) for (i = 0; i < 10; i++) { /* code */ }
d) for (int i = 0; i < 10; ++i) { /* code */ }

View Answer
A

Explanation: The correct syntax for a for loop in C includes the initialization, condition, and increment/decrement expressions inside parentheses, followed by a code block in braces.

 

3. What is the output of the following code?

#include <stdio.h>

int main() {
int x = 5;
printf("%d\n", x++);
return 0;
}

a) 5
b) 6
c) Compilation error
d) 0

View Answer
A

Explanation: The x++ operation prints the value of x before incrementing, so the output is 5.

 

4. Which of the following correctly defines a function in C?

a) int func(int x) { return x; }
b) int func x { return x; }
c) func(int x) { int x; }
d) function int func(int x) { return x; }

View Answer
A

Explanation: Option A correctly defines a function with a return type, parameter, and body.

 

5. What does the following code segment do?

int a = 10;
int b = 20;
a = b;
b = a;

a) Swaps the values of a and b
b) Sets a and b to the same value
c) Resets b to its initial value
d) Causes a compile-time error

View Answer
B

Explanation: After the assignment, a and b both have the same value, 20.

 

6. Which of the following is used to include a standard library in C?

a) #include <stdio.h>
b) import <stdio.h>
c) include <stdio.h>
d) require <stdio.h>

View Answer
A

Explanation: #include <stdio.h> is used to include the standard input-output library in C.

 

7. How do you declare a constant variable in C?

a) const int x = 10;
b) int const x = 10;
c) constant int x = 10;
d) const x = 10;

View Answer
A

Explanation: Both const int x = 10; and int const x = 10; are valid ways to declare a constant variable.

 

8. What is the purpose of the return statement in C?

a) To exit the program
b) To output a value to the console
c) To return a value from a function
d) To terminate a loop

View Answer
C

Explanation: The return statement is used to return a value from a function to its caller.

 

9. What will be the result of the following expression?

int x = 3;
int y = 4;
int z = x > y ? x : y;

a) 3
b) 4
c) 7
d) 0

View Answer
B

Explanation: The ternary operator ? returns y because x > y is false.

 

10. What does the sizeof operator do in C?

a) Returns the size of a variable or data type in bytes
b) Returns the number of elements in an array
c) Returns the length of a string
d) Returns the size of the memory allocated

View Answer
A

Explanation: size of returns the size of a variable or data type in bytes.

 

11. Which of the following is a correct way to declare an array in C?

a) int arr[10];
b) int arr(10);
c) int arr = [10];
d) array int arr[10];

View Answer
A

Explanation: int arr[10]; is the correct way to declare an array of 10 integers.

 

12. What is the result of the following code snippet?

int a = 2;
int b = 3;
int c = a * b + 5;

a) 11
b) 8
c) 6
d) 7

View Answer
A

Explanation: The expression evaluates to 2 * 3 + 5, which is 11.

 

13. How do you declare a pointer to an integer in C?

a) int *ptr;
b) int ptr*;
c) pointer int ptr;
d) int &ptr;

View Answer
A

Explanation: int *ptr; correctly declares a pointer to an integer.

 

14. What will be the output of the following code?

#include <stdio.h>

int main() {
int i = 10;
printf("%d\n", ++i);
return 0;
}

a) 10
b) 11
c) 9
d) 0

View Answer
B

Explanation: The ++i operation increments i before printing, so the output is 11.

 

15. Which function is used to allocate memory dynamically in C?

a) malloc()
b) alloc()
c) new()
d) free()

View Answer
A

Explanation: malloc() is used to allocate memory dynamically in C.

 

16. What will be the result of the following code?

#include <stdio.h>

int main() {
int arr[3] = {1, 2, 3};
printf("%d\n", arr[2]);
return 0;
}

a) 1
b) 2
c) 3
d) Compilation error

View Answer
C

Explanation: arr[2] accesses the third element of the array, which is 3.

 

17. What is the output of this code snippet?

#include <stdio.h>

int main() {
int a = 5;
int b = 3;
printf("%d\n", a / b);
return 0;
}

a) 1
b) 1.66
c) 2
d) 3

View Answer
1

Explanation: The division of integers results in an integer. 5 / 3 evaluates to 1.

 

18. How do you declare a float variable in C?

a) float num;
b) num float;
c) float num = 0;
d) float num = 0.0;

View Answer
A

Explanation: float num; is the correct syntax for declaring a float variable.

 

19. What is the purpose of the break statement in C?

a) To exit from a loop or switch statement
b) To pause the execution of a program
c) To jump to a specific part of code
d) To end the program execution

View Answer
A

Explanation: The break statement is used to exit from a loop or switch statement prematurely.

 

20. Which of the following correctly defines a struct in C?

a) struct Person { char name[50]; int age; };
b) struct Person { name[50] char; age int; };
c) Person { char name[50]; int age; };
d) struct Person { char name; int age; };

View Answer
A

Explanation: struct Person { char name[50]; int age; }; is the correct way to define a struct in C.

 

21. How do you access members of a structure in C?

a) Using the . operator
b) Using the -> operator
c) Using the & operator
d) Using the * operator

View Answer
A

Explanation: Structure members are accessed using the . operator for structure variables and -> for structure pointers.

 

22. What is the output of the following code?

#include <stdio.h>

int main() {
int a = 5;
int b = 10;
printf("%d\n", a == b);
return 0;
}

a) 1
b) 0
c) 5
d) 10

View Answer
B

Explanation: a == b is false, so the output is 0.

 

23. What will the following code print?

#include <stdio.h>

int main() {
int a = 4;
int b = 2;
int result = a % b;
printf("%d\n", result);
return 0;
}

a) 2
b) 1
c) 0
d) 4

View Answer
C

Explanation: a % b calculates the remainder of 4 / 2, which is 0.

 

24. Which operator is used to perform logical AND operation in C?

a) &&
b) &
c) |
d) ||

View Answer
A

Explanation: && is the logical AND operator in C.

25. What is the output of the following code?

#include <stdio.h>

int main() {
int i = 0;
while (i < 5) {
printf("%d ", i);
i++;
}
return 0;
}

a) 0 1 2 3 4
b) 1 2 3 4 5
c) 0 1 2 3 4 5
d) 1 2 3 4

View Answer
A

Explanation: The while loop prints values from 0 to 4.

 

26. What does the continue statement do in a loop?

a) Skips the current iteration and proceeds with the next iteration
b) Exits the loop
c) Breaks the loop
d) Restarts the loop

View Answer
A

Explanation: continue skips the rest of the current loop iteration and proceeds with the next iteration.

 

27. How do you define a macro in C?

a) #define NAME value
b) define NAME value
c) macro NAME = value
d) #macro NAME value

View Answer
A

Explanation: #define NAME value is the correct way to define a macro in C.

 

28. What is the output of the following code?

#include <stdio.h>

int main() {
printf("%c\n", 'A' + 1);
return 0;
}

a) ‘A’
b) ‘B’
c) ‘C’
d) 66

View Answer
B

Explanation: ‘A’ + 1 results in ‘B’ because ‘A’ has an ASCII value of 65.

 

29. Which keyword is used to define a constant in C?

a) const
b) static
c) final
d) immutable

View Answer
A

Explanation: The const keyword is used to define a constant in C.

 

30. What is the default return type of a function in C if not specified?

a) void
b) int
c) char
d) float

View Answer
B

Explanation: The default return type of a function in C is int if not specified.

 

31. Which function is used to read a string from the console?

a) scanf()
b) printf()
c) fgets()
d) gets()

View Answer
A

Explanation: scanf() can be used to read a string from the console, although fgets() is preferred for safety reasons.

 

32. How do you declare a two-dimensional array in C?

a) int arr[3][4];
b) int arr(3, 4);
c) int arr[3, 4];
d) int arr[3][4][];

View Answer
A

Explanation: int arr[3][4]; is the correct way to declare a two-dimensional array in C.

 

33. What will be the output of the following code?

#include <stdio.h>

int main() {
int a = 10;
int b = 20;
a += b;
printf("%d\n", a);
return 0;
}

a) 10
b) 20
c) 30
d) 40

View Answer
C

Explanation: a += b adds b to a, so a becomes 30.

 

34. Which of the following is used to access a variable from another file?

a) extern
b) static
c) auto
d) register

View Answer
A

Explanation: extern is used to declare a variable that is defined in another file.

 

35. What does the sizeof operator return when applied to an array?

a) The size of the array in bytes
b) The number of elements in the array
c) The size of the first element of the array
d) The total memory allocated for the array

View Answer
A

Explanation: sizeof applied to an array returns the total size of the array in bytes.

 

36. What will be the output of this code snippet?

#include <stdio.h>

int main() {
int x = 2;
int y = 3;
printf("%d\n", x * y++);
return 0;
}

a) 6
b) 7
c) 9
d) 5

View Answer
6

Explanation: y++ uses the value of y before incrementing, so x * y is 2 * 3, which is 6.

 

37. Which operator is used to perform bitwise OR in C?

a) |
b) ||
c) &
d) ^

View Answer
A

Explanation: | is used for bitwise OR operation in C.

 

38. What is the result of the following expression?

int x = 5;
int y = 10;
int z = (x < y) && (y > 5);

a) 0
b) 1
c) 5
d) 10

View Answer
B

Explanation: Both conditions (x < y) and (y > 5) are true, so the result of && is 1.

 

39. Which header file is required for using malloc() and free() functions?

a) stdlib.h
b) stdio.h
c) string.h
d) math.h

View Answer
A

Explanation: stdlib.h is the header file that includes declarations for malloc() and free() functions.

 

40. What is the output of this code snippet?

#include <stdio.h>

int main() {
int x = 4;
printf("%d\n", x--);
return 0;
}

a) 3
b) 4
c) 5
d) 0

View Answer
B

Explanation: The x– operation prints the value of x before decrementing, so the output is 4.

 

41. What is the result of the following code?

#include <stdio.h>

int main() {
int x = 3;
int y = x * 2 + 1;
printf("%d\n", y);
return 0;
}

a) 6
b) 7
c) 8
d) 9

View Answer
7

Explanation: x * 2 + 1 calculates to 3 * 2 + 1, which is 7.

 

42. What will be the output of this code snippet?

#include <stdio.h>

int main() {
int a = 2;
int b = 5;
printf("%d\n", a * (b - 1));
return 0;
}

a) 8
b) 10
c) 9
d) 7

View Answer
8

Explanation: The expression evaluates to 2 * (5 – 1), which is 8.

 

43. What is the correct syntax for a switch statement in C?

a) switch (expression) { case value: // code break; }
b) switch expression { case value: // code }
c) switch { expression case value: // code; }
d) switch (expression) { case value // code; break; }

View Answer
A

Explanation: Option A is the correct syntax for a switch statement in C.

 

44. How do you declare a char variable in C?

a) char ch;
b) char ch = ‘a’;
c) char ch = 0;
d) All of the above

[

expand title=”View Answer”]D

Explanation: All given options are valid ways to declare a char variable in C.[/expand]

 

45. What is the output of this code?

#include <stdio.h>

int main() {
int x = 3;
int y = 4;
printf("%d\n", x + y * 2);
return 0;
}

a) 11
b) 14
c) 10
d) 7

View Answer
11

Explanation: The expression evaluates to 3 + 4 * 2, which is 11 due to operator precedence.

 

46. Which of the following is a valid identifier in C?

a) int variable_name;
b) int 2variable;
c) int variable-name;
d) int variable name;

View Answer
A

Explanation: variable_name is a valid identifier. Identifiers cannot start with a digit or contain special characters other than _.

47. What does the & operator do in C?

a) Bitwise AND
b) Logical AND
c) Bitwise OR
d) Logical OR

View Answer
A

Explanation: & is used for bitwise AND operation in C.

 

48. How do you declare a constant integer in C?

a) const int x = 10;
b) int x = 10 const;
c) int const x = 10;
d) Both A and C

View Answer
D

Explanation: Both const int x = 10; and int const x = 10; are valid ways to declare a constant integer.

 

49. What is the output of the following code snippet?

#include <stdio.h>

int main() {
int x = 3;
int y = ++x * 2;
printf("%d\n", y);
return 0;
}

a) 6
b) 7
c) 8
d) 9

View Answer
8

Explanation: ++x increments x to 4, so 4 * 2 results in 8.

 

50. What is the correct way to define a float array in C?

a) float arr[10];
b) float arr(10);
c) float arr = [10];
d) float array[10];

View Answer
A

Explanation: float arr[10]; is the correct way to define a float array of 10 elements in C.

 

51. What will be the result of the following code?

#include <stdio.h>

int main() {
int a = 5;
int b = 2;
int c = a / b;
printf("%d\n", c);
return 0;
}

a) 2
b) 2.5
c) 3
d) 0

View Answer
2

Explanation: Integer division truncates the decimal part, so 5 / 2 results in 2.

 

52. What is the purpose of the default keyword in a switch statement?

a) Provides a default case if no other case matches
b) Exits from the switch statement
c) Defines the first case in a switch statement
d) Declares a switch statement

View Answer
A

Explanation: The default keyword is used to specify a default case that is executed if no other cases match.

 

53. Which of the following is not a valid C data type?

a) int
b) float
c) double
d) text

View Answer
D

Explanation: text is not a valid C data type. Valid types include int, float, and double.

 

54. What will be the result of the following code?

#include <stdio.h>

int main() {
int x = 4;
int y = 5;
printf("%d\n", x > y ? x : y);
return 0;
}

a) 4
b) 5
c) 9
d) 0

View Answer
B

Explanation: The ternary operator returns y because x > y is false.

 

55. What is the output of this code?

#include <stdio.h>

int main() {
int x = 3;
int y = 2;
int z = x + y * 2;
printf("%d\n", z);
return 0;
}

a) 7
b) 8
c) 9
d) 6

View Answer
7

Explanation: The expression evaluates to 3 + 2 * 2, which is 7 due to operator precedence.

 

56. Which of the following is a valid way to comment in C?

a) /* This is a comment */
b) // This is a comment
c) # This is a comment
d) — This is a comment

View Answer
A

Explanation: Both /* */ and // are valid ways to comment in C.

 

57. What does the return 0; statement do in the main() function?

a) Indicates that the program has completed successfully
b) Exits the program with an error
c) Restarts the main() function
d) Causes a syntax error

View Answer
A

Explanation: return 0; indicates that the program has completed successfully and returns control to the operating system.

 

58. What will be the result of the following code?

#include <stdio.h>

int main() {
int a = 7;
int b = 5;
printf("%d\n", a % b);
return 0;
}

a) 1
b) 2
c) 7
d) 5

View Answer
2

Explanation: a % b calculates the remainder of 7 / 5, which is 2.

 

59. How do you declare a variable that can hold a large integer in C?

a) long int
b) big int
c) large int
d) int64

View Answer
A

Explanation: long int is used to declare a variable that can hold a larger integer value in C.

 

60. What is the purpose of the static keyword in C?

a) To restrict the visibility of a variable or function to its file
b) To allocate memory dynamically
c) To define a global variable
d) To declare a variable as a constant

View Answer
A

Explanation: static restricts the visibility of a variable or function to its file or function scope.

 

61. What does the continue statement do inside a loop?

a) Skips the rest of the current iteration and proceeds with the next iteration
b) Ends the loop execution
c) Breaks out of the loop
d) Exits the loop and the program

View Answer
A

Explanation: The continue statement skips the remaining code in the current loop iteration and moves to the next iteration.

 

62. How do you include a user-defined header file in C?

a) #include “header.h”
b) #include <header.h>
c) #import “header.h”
d) #require “header.h”

View Answer
A

Explanation: #include “header.h” is used to include a user-defined header file.

 

63. What will be the output of this code snippet?

#include <stdio.h>

int main() {
int a = 4;
int b = 2;
printf("%d\n", a * (b + 2));
return 0;
}

a) 12
b) 8
c) 14
d) 10

View Answer
12

Explanation: The expression evaluates to 4 * (2 + 2), which is 12.

 

64. What does the ++ operator do in C?

a) Increments a variable’s value by 1
b) Decrements a variable’s value by 1
c) Multiplies a variable’s value by 2
d) Divides a variable’s value by 2

View Answer
A

Explanation: The ++ operator increments a variable’s value by 1.

 

65. Which keyword is used to define a function prototype in C?

a) void
b) extern
c) static
d) typedef

View Answer
B

Explanation: The extern keyword is used to declare a function prototype in C, indicating that the function is defined elsewhere.

 

66. What is the output of the following code snippet?

#include <stdio.h>

int main() {
int x = 5;
printf("%d\n", x-- - 1);
return 0;
}

a) 4
b) 5
c) 6
d) 3

View Answer
4

Explanation: x– uses the value of x before decrementing, so 5 – 1 is 4.

 

67. Which operator is used for pointer arithmetic in C?

a) +
b) –
c) *
d) All of the above

View Answer
D

Explanation: All listed operators can be used for pointer arithmetic in C, including +, -, and *.

 

68. How do you convert an integer to a float in C?

a) float
b) float(x)
c) x.float
d) static_cast<float>(x)

View Answer
A

Explanation: The correct way to convert an integer to a float in C is by using type casting with float.

 

69. What will be the result of the following code?

#include <stdio.h>

int main() {
int x = 6;
int y = x % 3;
printf("%d\n", y);
return 0;
}

a) 1
b) 2
c) 0
d) 3

View Answer
0

Explanation: x % 3 calculates the remainder of 6 / 3, which is 0.

 

70. Which of the following is the correct way to declare a float variable in C?

a) float f;
b) float f = 1.0;
c) float f = 0.0;
d) All of the above

View Answer
D

Explanation: All options are valid ways to declare a float variable in C.

 

71. What is the output of the following code snippet?

#include <stdio.h>

int main() {
int x = 10;
int y = 5;
printf("%d\n", x / y);
return 0;
}

a) 2
b) 5
c) 10
d) 15

View Answer
2

Explanation: x / y calculates to 10 / 5, which is 2.

 

72. What will be the result of the following code snippet?

#include <stdio.h>

int main() {
int x = 10;
int y = x % 4;
printf("%d\n", y);
return 0;
}

a) 2
b) 0
c) 1
d) 3

View Answer
2

Explanation: x % 4 calculates the remainder of 10 / 4, which is 2.

 

73. What is the output of the following code snippet?

#include <stdio.h>

int main() {
int a = 6;
int b = 2;
printf("%d\n", a / b * 2);
return 0;
}

a) 6
b) 8
c) 4
d) 12

View Answer
6

Explanation: The expression evaluates to 6 / 2 * 2, which is 6 due to operator precedence.

 

74. How do you declare a variable that can hold a decimal number in C?

a) float
b) decimal
c) number
d) int

View Answer
A

Explanation: float is used to declare a variable that can hold a decimal number in C.

 

75. What is the result of the following code snippet?

#include <stdio.h>

int main() {
int x = 9;
int y = x / 4;
printf("%d\n", y);
return 0;
}

a) 1
b) 2
c) 3
d) 4

View Answer
2

Explanation: x / 4 calculates to 9 / 4, which is 2 with integer division.

 

76. What is the correct syntax for defining a function in C?

a) returnType functionName(parameters) { // code }
b) functionName(parameters) { // code }
c) returnType functionName { // code }
d) functionName returnType(parameters) { // code }

View Answer
A

Explanation: The correct syntax for defining a function in C is returnType functionName(parameters) { // code }.

 

77. Which of the following is used to allocate memory dynamically in C?

a) malloc()
b) alloc()
c) memory()
d) new()

View Answer
A

Explanation: malloc() is used to allocate memory dynamically in C.

 

78. What is the output of the following code snippet?

#include <stdio.h>

int main() {
int x = 7;
printf("%d\n", x++);
return 0;
}

a) 7
b) 8
c) 6
d) 9

View Answer
A

Explanation: x++ prints the value of x before incrementing, so the output is 7.

 

79. What is the correct way to comment out a block of code in C?

a) /* This is a block comment */
b) // This is a block comment
c) # This is a block comment
d) — This is a block comment

View Answer
A

Explanation: The /* */ syntax is used to comment out a block of code in C.

 

80. Which of the following operators has the highest precedence in C?

a) *
b) +
c) =
d) ++

View Answer
D

Explanation: The ++ operator (increment) has the highest precedence among the operators listed.

 

81. What is the output of this code snippet?

#include <stdio.h>

int main() {
int x = 5;
int y = 2;
printf("%d\n", x % y);
return 0;
}

a) 1
b) 2
c) 0
d) 5

View Answer
1

Explanation: x % y calculates the remainder of 5 / 2, which is 1.

 

82. What does the #include <stdio.h> directive do in C?

a) Includes the standard input/output library
b) Includes user-defined functions
c) Includes the math library
d) Includes the string manipulation library

View Answer
A

Explanation: #include <stdio.h> includes the standard input/output library which provides functions like printf and scanf.

 

83. What will be the result of the following code snippet?

#include <stdio.h>

int main() {
int a = 3;
int b = 4;
printf("%d\n", a + b * 2);
return 0;
}

a) 10
b) 11
c) 14
d) 7

View Answer
11

Explanation: The expression evaluates to 3 + 4 * 2, which is 11 due to operator precedence.

 

84. Which function is used to find the length of a string in C?

a) strlen()
b) strlength()
c) length()
d) size()

View Answer
A

Explanation: strlen() is used to find the length of a string in C.

 

85. What is the result of the following code?

#include <stdio.h>

int main() {
int x = 8;
int y = x / 3;
printf("%d\n", y);
return 0;
}

a) 2
b) 3
c) 4
d) 1

View Answer
2

Explanation: x / 3 calculates to 8 / 3, which is 2 with integer division.

 

 

86. How do you declare a pointer to an integer in C?

a) int *ptr;
b) int ptr*;
c) pointer int;
d) int &ptr;

View Answer
A

Explanation: int *ptr; declares a pointer to an integer in C.

 

87. What does the break statement do in a loop?

a) Exits the loop
b) Continues to the next iteration
c) Restarts the loop
d) Exits the loop and the program

View Answer
A

Explanation: The break statement exits the loop immediately.

 

88. What is the output of the following code?

#include <stdio.h>

int main() {
int x = 10;
int y = 3;
printf("%d\n", x / y);
return 0;
}

a) 3
b) 4
c) 10
d) 30

View Answer
3

Explanation: x / y calculates to 10 / 3, which is 3 with integer division.

 

89. What is the correct syntax to declare an array of 5 integers in C?

a) int arr[5];
b) int arr(5);
c) int arr = [5];
d) int arr[5] = {0};

View Answer
A

Explanation: int arr[5]; is the correct syntax to declare an array of 5 integers in C.

 

90. What is the purpose of the sizeof operator in C?

a) Determines the size of a data type or variable
b) Allocates memory dynamically
c) Defines the size of an array
d) Compares the size of two variables

View Answer
A

Explanation: The sizeof operator is used to determine the size of a data type or variable in bytes.

 

91. What is the result of the following code snippet?

#include <stdio.h>

int main() {
int x = 4;
int y = x++;
printf("%d\n", y);
return 0;
}

a) 4
b) 5
c) 6
d) 3

View Answer
4

Explanation: x++ uses the value of x before incrementing, so y is 4 and then x becomes 5.

 

92. What is the correct syntax for defining a struct in C?

a) struct StructName { // members };
b) struct { // members } StructName;
c) StructName struct { // members };
d) struct StructName;

View Answer
A

Explanation: The correct syntax for defining a struct in C is struct StructName { // members };.

 

93. What is the output of the following code snippet?

#include <stdio.h>

int main() {
int x = 7;
int y = 4;
printf("%d\n", x / y);
return 0;
}

a) 1
b) 2
c) 3
d) 4

View Answer
1

Explanation: x / y calculates to 7 / 4, which is 1 with integer division.

 

94. What is the purpose of the continue statement in C?

a) Skips the remaining code in the current iteration and proceeds to the next iteration of the loop
b) Exits the loop
c) Restarts the loop
d) Exits the loop and the program

View Answer
A

Explanation: The continue statement skips the remaining code in the current iteration of the loop and proceeds with the next iteration.

 

95. What is the correct way to initialize an integer array with values in C?

a) int arr[] = {1, 2, 3, 4};
b) int arr[4] = {1, 2, 3, 4};
c) int arr = {1, 2, 3, 4};
d) int arr[4] = (1, 2, 3, 4);

View Answer
B

Explanation: int arr[4] = {1, 2, 3, 4}; is the correct way to initialize an integer array with values in C.

 

96. What will be the result of the following code snippet?

#include <stdio.h>

int main() {
int x = 5;
printf("%d\n", ++x * 2);
return 0;
}

a) 10
b) 12
c) 11
d) 20

View Answer
12

Explanation: ++x increments x to 6, so 6 * 2 results in 12.

 

97. Which of the following is used to handle errors in C?

a) error()
b) assert()
c) debug()
d) exception()

View Answer
B

Explanation: assert() is used to handle errors in C by verifying assumptions made by the program.

 

98. What is the output of the following code snippet?

#include <stdio.h>

int main() {
int x = 5;
int y = 10;
printf("%d\n", x * y / 5);
return 0;
}

a) 10
b) 5
c) 50
d) 20

View Answer
10

Explanation: x * y / 5 calculates to 5 * 10 / 5, which is 10.

 

99. How do you declare a constant float in C?

a) const float x = 10.0;
b) float const x = 10.0;
c) const float x = 10.0f;
d) Both A and B

View Answer
D

Explanation: Both const float x = 10.0; and float const x = 10.0; are valid ways to declare a constant float in C.

 

100. What is the output of the following code snippet?

#include <stdio.h>

int main() {
int x = 2;
int y = 3;
printf("%d\n", x * y + y);
return 0;
}

a) 5
b) 6
c) 9
d) 11

View Answer
9

Explanation: x * y + y calculates to 2 * 3 + 3, which is 9.

Facebook
WhatsApp
LinkedIn

All Subject MCQs

Current Affairs MCQs

Fine Arts MCQs

Physiotherapy MCQs

Microsoft Azure MCQs

General Knowledge MCQs

Islamic Studies MCQs

Jammu and Kashmir Studies MCQs

English Basic MCQ

Machine Design MCQs

Physical Education MCQs

Nursing MCQs

Report writing MCQs

WEB ONTOLOGY MCQs

Geography MCQs

UDC and LDC Clerk MCQs

Physics Basic MCQs

E-COMMERCE MCQs

Management Sciences MCQs

Land Records MCQs

Chemistry MCQs

HTML MCQS

Pedagogy MCQs

Terrorism in Pakistan MCQs

Leadership MCQs

Cascading Style Sheets (CSS) MCQS

Psychology MCQs

Engineering MCQs

PHP MCQS

Botany MCQs

Biology MCQs

Artificial Intelligence (AI) MCQs

Zoology MCQs

Math MCQs

Data Science MCQs

Agriculture MCQs

Statistics MCQs

C++ Multiple-Choice

Current Affairs MCQs

Economics MCQs

Data Structures MCQs

Everyday Science MCQs

Philosophy MCQs

Operating System MCQs

Pakistan Studies MCQs

Political Science MCQs

UNIX Operating System MCQs

Environmental MCQs

Ethics MCQs

DISCRETE MATHEMATICS MCQS

Library science MCQs

Social Studies MCQs

Computer Basic MCQs

Dental MCQs

Computer Science MCQs

Automata Theory MCQs

Digital Image Processing MCQs

Artificial Intelligence (AI) MCQs

Mobile Android Applications Mcqs

Mobile android applications MCQs

Data Science MCQs

Multimedia System MCQs

Graph Algorithms MCQs

C++ Multiple-Choice

Real-Time Systems MCQs

CAD MCQs

Data Structures MCQs

C Programming Mcqs

Embedded System MCQs

Operating System MCQs

Computer Basic MCQs

Web Security and forensics MCQs

UNIX Operating System MCQs

OOP MCQs

Python MCQs

Digital Logic Design MCQs

LINUX Operating System MCQs

Microsoft Office MCQs

Database System MCQs

Data Mining MCQs

Internet and Email MCQs

Compiler Construction MCQs

Software Architecture MCQs

Computer general knowledge MCQs

Computer Architecture MCQs

Software Formal Methods MCQs

Social Networks MCQs

Software Requirement Engineering MCQs

Software Project Management MCQs

Graphic designing MCQs

Software Testing MCQs

Object-Oriented Analysis And Design MCQs

Photoshop MCQs

Software quality Assurance MCQs

UML MCQs

Corel Draw MCQs

Software Fault Tolerance MCQS

Computer Graphics MCQs

Parallel and Distributed Computing MCQs

Software Risk Management MCQS

Network MCQs

  • Home
  • About
  • Contact
  • Privacy Policy
    • Terms of Use
    • Cookie Privacy Policy
    • California Consumer Privacy Act (CCPA)
    • DMCA
  • Free Tools
Menu
  • Home
  • About
  • Contact
  • Privacy Policy
    • Terms of Use
    • Cookie Privacy Policy
    • California Consumer Privacy Act (CCPA)
    • DMCA
  • Free Tools

© 2024 All rights Reserved. Design by Arslan

Powered by Subject Nest