✨ BCA JUL24 Batch ✨

Join Our WhatsApp Group

Anukasif Pic

C Programming - Q&A for BCA 1st Semester

Learn C programming Questions answers through examples.


Important MCQs of C Programming for BCA 1st Semester Exam

Download PDF

Important Questions of C- Programming for BCA 1st Semester Exam!

1. What is Arithmetic and Logic Unit?

The Arithmetic and Logic Unit (ALU) is a part of the CPU that performs arithmetic operations (like addition, subtraction, multiplication, and division) and logical operations (like comparisons, AND, OR, NOT). It is responsible for mathematical calculations and decision-making in a computer.

2. What is a Control Unit?

The Control Unit (CU) is a part of the CPU that directs the flow of instructions and data within the computer. It interprets instructions from the memory and controls the execution of operations by coordinating with other components like ALU and memory.

3. What is a Compiler and Interpreter?

A compiler translates the entire program from high-level language to machine code at once, creating an executable file. An interpreter translates and executes the program line by line, without generating an executable file.

4. What is a Linker, Dynamic Linker, and Static Linker?

A linker combines multiple object files into a single executable file. A dynamic linker links shared libraries at runtime. A static linker links all required libraries into the executable at compile time.

5. What is a Variable?

A variable is a named memory location used to store data values that can be changed during program execution.

6. What is Data Types?

Data types specify the type of data a variable can store, such as integers, floating-point numbers, characters, etc. Example: int, float, char.

7. What are Operators and Expressions in C?

Operators are symbols used to perform operations on variables, like +, -, *, /. Expressions are combinations of variables, constants, and operators that produce a value, e.g., a + b.

8. What are Functions?

Functions are reusable blocks of code designed to perform a specific task. They help in breaking a program into smaller, manageable parts. Example: main(), printf().

9. What is a Compound Statement?

A compound statement is a group of multiple statements enclosed within { } that are executed together.

10. Difference between Conditional Statement and Switch Statement?

Conditional Statement
Uses if-else to execute specific code based on conditions.
Supports a range of conditions.
More flexible but can be complex.

Switch Statement
Uses multiple case labels to handle different values of a variable.
Works with discrete values like integers or characters.
Easier to read for multi-value conditions.

11. What is While Loop and Do While Loop?

A while loop repeatedly executes a block of code as long as the condition is true. The condition is checked before execution.

A do-while loop executes the block of code at least once, then checks the condition to decide further execution.

12. Difference between Arrays and Functions?

Arrays store multiple values of the same data type under one name. Functions perform specific tasks and can be called multiple times with different arguments.

13. What is 1-Dimensional and 2-Dimensional Array?

A 1-Dimensional array is a linear list of elements stored in a single row. Example: int arr[5];

A 2-Dimensional array stores data in rows and columns like a table. Example: int arr[3][3];

14. What is a Function Argument?

A function argument is a value passed to a function when it is called. It allows the function to use external data for its operation.

15. What is Local Variable and Global Variable?

A local variable is declared inside a function and is accessible only within that function.

A global variable is declared outside all functions and can be accessed by any function in the program.

16. Write History of C and Explain Its Features.

History: C was developed by Dennis Ritchie in 1972 at Bell Labs for the UNIX operating system.

Features:

17. What is an Operator? Explain Its Types.

An operator is a symbol used to perform operations on variables and values. Types:

18. What is Operator Precedence and Associativity?

Operator Precedence: Determines the order in which operators are evaluated. Example: * has higher precedence than +.

Associativity: Defines the direction of execution for operators with the same precedence. Example: Left-to-right for + and *.

19. Explain Conditional Control Statement.

Conditional control statements like if, if-else, and switch allow decision-making in a program by executing code based on conditions.

20. Explain Break and Continue Statement.

Break: Exits a loop or switch statement immediately.

Continue: Skips the current iteration of a loop and moves to the next iteration.

21. Explain Loop Control Structure with Example.

Loop control structures like for, while, and do-while are used to execute a block of code repeatedly.

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

Output: 0 1 2 3 4

22. What is an Array? Explain 2D Array with Memory Representation.

An array is a collection of elements of the same data type stored in contiguous memory locations.

A 2D array is a collection of elements arranged in rows and columns.

Memory Representation:

Row\Col Col 0 Col 1 Col 2
Row 0 arr[0][0] arr[0][1] arr[0][2]
Row 1 arr[1][0] arr[1][1] arr[1][2]

Memory is stored row by row in a linear fashion.

23. Define Pointer and Explain All Functions of DMA (Dynamic Memory Allocation).

A pointer is a variable that stores the memory address of another variable. Example: int *ptr;

DMA Functions:

24. What are Structure and Union? How to Differentiate Them?

A structure groups related variables of different data types under one name.

A union is similar but shares memory for all its members, storing only one value at a time.

Difference Between Structure and Union:

Structure Union
Allocates separate memory for each member. All members share the same memory location.
Stores multiple values simultaneously. Stores only one value at a time.

25. Define a Macro. How to Substitute Macro Directives in a Program?

A macro is a preprocessor directive used to define constants or code snippets.

It substitutes the macro name with its definition during preprocessing.

Example:

#define PI 3.14  
      #define SQUARE(x) (x * x)

In the program, PI will be replaced with 3.14, and SQUARE(5) will be replaced with (5 * 5).

26. What is an Operator and Its Types? Explain Left Shift and Right Shift Operator.

An operator is a symbol used to perform operations on variables and values.

Types of Operators:

Left Shift (<<) and Right Shift (>>):

27. Write a Program to Swap Two Integer Numbers Without Using a Temporary Variable.

#include <stdio.h>
      int main() {
          int a = 5, b = 10;
          a = a + b;
          b = a - b;
          a = a - b;
          printf("a = %d, b = %d\n", a, b);
          return 0;
      }

28. Why is C Called a Mid-Level Programming Language?

C is called a mid-level programming language because:

29. What Are the Basic Data Types Supported in the C Programming Language?

Basic data types in C:

30. What Are Preprocessor Directives in C? Explain Macros with a Suitable Example.

Preprocessor directives are instructions processed before compilation, like #include, #define, and #ifdef.

Macros are defined using #define and replaced before compilation.

Example:

#include <stdio.h>
      #define PI 3.14
      int main() {
          printf("Value of PI: %f\n", PI);
          return 0;
      }

31. What is Recursion in C? Explain with an Example.

Recursion is a process where a function calls itself to solve a smaller problem until a base condition is met.

Example:

#include <stdio.h>
      int factorial(int n) {
          if (n == 0) return 1; 
// Base condition return n * factorial(n - 1); } int main() { printf("Factorial of 5: %d\n",
factorial(5)); return 0; }

32. What is the Difference Between Local and Global Variables in C?

Local Variable
Declared inside a function. Accessible only within that function.

Global Variable
Declared outside all functions. Accessible by all functions.

33. What is the Difference Between Type Casting and Type Conversion?

Type Casting (Explicit): Done manually using (type) syntax. Example: (float)a / b;

Type Conversion (Implicit): Done automatically by the compiler. Example: int x = 3.5;x becomes 3.

34. What Are Functions and Their Types? Explain the Application of Functions in C.

A function is a reusable block of code to perform specific tasks.

Types:

Application: Functions help in modular programming, making code reusable and easier to debug.

35. What is the Difference Between Macro and Functions? Explain the Various Types of Storage Class in C.

Difference Between Macro and Function:

Macro Function
Preprocessed, no runtime overhead. Executed at runtime.
No type-checking. Supports type-checking.
Example: #define SQUARE(x) x*x Example: int square(int x) { return x*x; }

Storage Classes in C:

36. What is the Difference Between Call by Value and Call by Reference? Explain with a Suitable Example.

Call by Value: A copy of the actual parameter is passed to the function. Changes made in the function do not affect the original value.

Call by Reference: The memory address of the parameter is passed to the function. Changes made in the function affect the original value.

Example:

#include <stdio.h>
      void callByValue(int x) {
          x = 10; // Changes local copy
      }
      void callByReference(int *y) {
          *y = 10; // Changes original value
      }
      int main() {
          int a = 5, b = 5;
          callByValue(a);
          callByReference(&b);
          printf("a = %d, b = %d\n", a, b);
          return 0;
      }

Output: a = 5, b = 10

37. Write a C Program to Check Whether a Number is Prime or Not.

#include <stdio.h>
      int main() {
          int n, i, flag = 1;
          printf("Enter a number: ");
          scanf("%d", &n);
          if (n <= 1) flag = 0; // Not prime
          for (i = 2; i <= n / 2; i++) {
              if (n % i == 0) {
                  flag = 0;
                  break;
              }
          }
          if (flag) printf("%d is a prime 
number.\n", n); else printf("%d is not a prime
number.\n", n); return 0; }

38. What is Static Memory Allocation and Dynamic Memory Allocation?

Static Memory Allocation: Memory is allocated at compile time, and the size cannot be changed during runtime. Example: int arr[10];.

Dynamic Memory Allocation: Memory is allocated at runtime using functions like malloc(), calloc(), and can be resized using realloc().

39. Write a Program to Check Whether a String is a Palindrome or Not.

#include <stdio.h>
      #include <string.h>
      int main() {
          char str[100], rev[100];
          printf("Enter a string: ");
          scanf("%s", str);
          strcpy(rev, str);
          strrev(rev);
          if (strcmp(str, rev) == 0) 
printf("The string is a palindrome.\n"); else printf("The string is not a
palindrome.\n"); return 0; }

40. What is the Use of printf() and scanf() Functions in C? Explain Format Specifiers.

printf(): Used to display output. Example: printf("Hello");

scanf(): Used to take input. Example: scanf("%d", &var);

Format Specifiers:

41. What are the Key Features in the C Programming Language?

42. What is a C program?

A C program is a set of instructions that tell the computer how to perform a task. C is a high-level programming language used for system and application development.

43. How does a C program work?

C programs are written in plain text and then compiled into machine code. The process involves writing the program, compiling it, and executing it.

44. What are variables in C?

In C, variables are used to store data. A variable is a named memory location used to store values that can be modified during program execution.