0% found this document useful (0 votes)
22 views3 pages

C Programming Theory QA

The document outlines important theoretical questions and answers related to C programming, covering features, structure, data types, operators, loops, functions, arrays, pointers, and file handling. It explains key concepts such as the difference between compilers and interpreters, local and global variables, and structures versus unions. Additionally, it provides examples and syntax for various C programming constructs.

Uploaded by

a.h.bershy2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

C Programming Theory QA

The document outlines important theoretical questions and answers related to C programming, covering features, structure, data types, operators, loops, functions, arrays, pointers, and file handling. It explains key concepts such as the difference between compilers and interpreters, local and global variables, and structures versus unions. Additionally, it provides examples and syntax for various C programming constructs.

Uploaded by

a.h.bershy2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C Programming – Important Theory Questions with

Answers

1. Explain the features of C language.


- General purpose, structured, mid-level language.
- Portable and efficient.
- Supports modular programming (functions).
- Rich library of operators and functions.
- Used for system programming and applications.

2. Explain the structure of a C program with an example.


A C program has:
1. Preprocessor directives (#include <stdio.h>).
2. main() function (starting point).
3. Variable declarations.
4. Statements and logic.
5. Return statement.

Example:
#include <stdio.h>
int main() {
int a=5,b=10,sum;
sum=a+b;
printf("Sum=%d",sum);
return 0;
}

3. What is the difference between a compiler and an interpreter?


- Compiler: Translates entire program at once (C uses compiler).
- Interpreter: Executes line by line (Python uses interpreter).

4. What are keywords, identifiers, constants, and variables in C?


- Keywords: Reserved words (int, float, return).
- Identifiers: User-defined names for variables/functions.
- Constants: Fixed values (e.g., 10, 3.14, 'A').
- Variables: Named storage that can change value.

5. Explain different data types in C with examples.


Basic: int, float, char, double
Derived: arrays, pointers, structures, functions
Void: no value

Example:
int age=20;
float marks=85.5;
char grade='A';

6. Explain the types of operators in C.


Arithmetic: +, -, *, /, %
Relational: >, <, ==, !=
Logical: &&, ||, !
Assignment: =
Increment/Decrement: ++, --
7. Differentiate between '=' and '=='.
- '=' is assignment operator (a=5).
- '==' is equality check (a==5).

8. What is the difference between while and do-while loop?


- while: condition checked first, may run 0 times.
- do-while: executes at least once, condition checked later.

9. Write the syntax of if-else and switch with examples.


if(condition) {
statements;
} else {
statements;
}

switch(choice) {
case 1: ...; break;
case 2: ...; break;
default: ...;
}

10. What is the difference between break and continue statements?


- break: exits loop/switch completely.
- continue: skips current iteration, moves to next.

11. What is an array? Explain 1D and 2D arrays with examples.


Array = collection of same data type.

1D: int marks[5] = {10,20,30,40,50};


2D: int mat[2][2] = {{1,2},{3,4}};

12. What is the difference between array and pointer?


- Array: collection of elements, fixed size.
- Pointer: variable storing address of another variable.

13. Write the syntax for declaring and initializing arrays.


int arr[5] = {1,2,3,4,5};

14. What are string handling functions in C?


strlen() – length of string
strcpy() – copy string
strcmp() – compare strings
strcat() – join strings

15. Differentiate between character array and string.


- Char array: collection of characters.
- String: char array ending with null '\0'.

16. What is a function? Explain call by value and call by reference.


Function = block of reusable code.
Call by value = copy passed, original unchanged.
Call by reference = address passed, original changes.

17. What is the use of pointers in C? Give examples.


Pointers store addresses, used for dynamic memory, arrays, functions.
Example:
int a=10; int *p; p=&a;

18. What is recursion? Give one example.


Recursion = function calling itself.
Example: factorial function.

19. What is the difference between local and global variables?


- Local: declared inside function, used only there.
- Global: declared outside, used in entire program.

20. What is the difference between formal and actual parameters?


- Formal: variables in function definition.
- Actual: values passed during function call.

21. What is a structure? How is it different from an array?


Structure: collection of different data types.
Array: collection of same data type.

22. Write the syntax to declare and access structure members.


struct Student {int roll; char name[20];};
struct Student s1;
s1.roll=1;

23. Differentiate between structure and union.


- Structure: all members have separate memory.
- Union: members share same memory location.

24. Explain file handling functions: fopen, fprintf, fscanf, fclose.


fopen() – open file
fprintf() – write to file
fscanf() – read from file
fclose() – close file

25. What is the difference between text file and binary file in C?
- Text file: stores data in readable format.
- Binary file: stores data in binary (faster, smaller).

You might also like