Programming C | 10 Question with answer

  1. What is the difference between int and float data types in C?
  • Answer: int is used for whole numbers (integers) while float is used for numbers with decimal points (floating-point numbers).
  1. What is the purpose of the main function in C?
  • Answer: The main function is the entry point of a C program. Every C program execution begins from the main function.
  1. How do you declare an array in C?
  • Answer: You can declare an array by specifying its data type, size enclosed in square brackets, and a variable name. For example: int numbers[10];
  1. Explain the syntax for a simple if statement in C.
  • Answer: if (condition) { // code to execute if condition is true } else { // code to execute if condition is false (optional) }
  1. What is the difference between the = and == operators in C?
  • Answer: = is the assignment operator used to assign a value to a variable. == is the comparison operator used to check if two values are equal.
  1. What does the break statement do inside a loop in C?
  • Answer: The break statement exits the loop immediately, even if the loop condition is still true.
  1. What is a pointer variable in C?
  • Answer: A pointer variable stores the memory address of another variable. It allows you to indirectly access and modify the value of another variable.
  1. How do you read user input using scanf function in C?
  • Answer: You can use scanf function with format specifiers like %d for integers or %c for characters to read user input and store it in variables.
  1. What are the different storage classes (auto, static, extern) in C?
  • Answer: Storage classes define the scope and lifetime of variables. auto (default) creates a variable that exists only within its block scope. static creates a variable that retains its value between function calls. extern declares a variable that is defined in another file.
  1. What is the difference between compilation and execution in C programming?
  • Answer: Compilation translates the C code into machine code understandable by the computer. Execution runs the machine code to perform the intended operations of the program.

Leave a Reply

Your email address will not be published. Required fields are marked *