Unit-1: - Introduction to ‘C’ Language:
1. What is a Program?
A program is a sequence of instructions written to perform a specified task with a computer.
In C, a program typically includes variables, expressions, functions, and control statements to
process data and produce output.
2. What is Software?
Software is a set of programs and associated documentation and data that operates a computer
system. It falls into two categories:
• System Software (e.g., Operating Systems, Compilers)
• Application Software (e.g., MS Word, Browsers)
3. What is an Instruction in C?
An instruction is a statement in C that tells the computer to perform a specific operation.
Types include:
• Input/Output instructions (scanf, printf)
• Arithmetic instructions (a = b + c;)
• Control instructions (if, while, for)
4. What is Debugging?
Debugging is the process of identifying, analyzing, and resolving errors (bugs) in a program.
It ensures the program runs correctly and efficiently. Tools such as IDE debuggers or the gdb
debugger in Linux help in debugging C programs.
5. What are Compilation and Execution in C?
• Compilation: Converts source code (.c) into machine code (object files) using a
compiler.
• Execution: Runs the machine code as a program to perform the desired operations.
Steps:
1. Write source code → file.c
2. Compile it → file.o
3. Link it → file.exe
4. Run it → Executed output
6. What is the Difference Between Header Files and Library Files?
Header Files (.h) Library Files (.lib/.dll/.a)
Content Function declarations, macros Actual code definitions
Usage Included via #include in source code Linked by the linker during compilation
Examples stdio.h, math.h libc.lib, libm.a
7. What is a Compiler and How is it Different from an Interpreter?
Feature Compiler Interpreter
Translation Translates entire program at Translates one line at a time
once
Speed Faster execution Slower execution
Output Generates executable file Does not generate an
executable
Example gcc, Turbo C Python, JavaScript (Node.js)
8. What is a Procedure-Oriented Language?
A Procedure-Oriented Programming (POP) language emphasizes functions and procedures to
break a problem into smaller parts. Key features:
• Focus on process (functions)
• Code is organized as functions
• Data flows freely between functions
C is a classic example of a procedure-oriented language.
9. What is the Importance of C Language?
• Foundation of modern languages like C++, Java
• High performance and efficient execution
• Portable across platforms
• Supports system-level programming
• Rich standard library and flexibility
10. What is the Basic Structure of a C Program?
#include <stdio.h> // Header File
int main() { // Main Function
int a, b, sum; // Variable Declaration
printf("Enter two numbers: ");
scanf("%d %d", &a, &b); // Input
sum = a + b; // Processing
printf("Sum = %d", sum); // Output
return 0;
}
11. What is an Algorithm?
An algorithm is a well-defined, step-by-step process for solving a problem or performing a
task.
Characteristics:
• Finiteness
• Definiteness
• Input and Output
• Effectiveness
Example: Algorithm to Add Two Numbers
1. Start
2. Read two numbers A and B
3. Calculate Sum = A + B
4. Display Sum
5. End
12. What is a Flowchart?
A flowchart is a visual representation of an algorithm using standard symbols:
• Oval: Start/End
• Parallelogram: Input/output
• Rectangle: Process
• Diamond: Decision
Example: Flowchart for Adding Two Numbers
[Start]
|
[Input A and B]
|
[SUM = A + B]
|
[Print SUM]
|
[End]
Constants, Variables & Data Types in C
13. What is the difference between algorithm and flowchart?
Aspect Algorithm Flowchart
A step-by-step textual procedure to A visual diagram representing steps of
Definition
solve a problem an algorithm
Written in natural or structured Uses symbols like arrows, rectangles,
Format
language (pseudo code) diamonds, etc.
Readability Easier to write and modify Easier to understand at a glance
Shows the flow of control or logic
Purpose Describes logic and process in words
pictorially
Symbols Specific symbols like Start/End (oval),
No specific symbols
Used Process (rectangle)
Example Planning, documentation, teaching
Programming, logic development
Usage algorithm flow
Best For Writing and analysing logic Presenting or explaining logic visually
14. What is the role of return 0; in C?
It indicates successful program termination to the operating system.
15. What are header files in C? Give examples.
Header files contain declarations of functions and macros.
Examples: #include <stdio.h>, #include <math.h>
16. Explain the purpose of the main() function in C.
main() is the entry point of every C program where execution begins.
Unit-2:- Constants, Variables & Data Types in ‘C’:
1. What is the Character Set in C?
The character set in C includes all valid characters that can be used in writing C programs. It
includes:
• Letters: A-Z, a-z
• Digits: 0-9
• Special Characters: +, -, *, /, =, @, #, etc.
• Whitespace characters: Space, Tab, Newline
• Escape sequences: \n, \t, \\ etc.
2. What are C Tokens?
Tokens are the smallest elements of a C program that are meaningful to the compiler. Types
of tokens include:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Operators
6. Special Symbols
3. What are Keywords and Identifiers?
• Keywords are reserved words that have special meaning in C. They cannot be used as
variable names.
Examples: int, float, return, if, else, void, char, etc.
• Identifiers are the names given to variables, functions, arrays, etc., by the
programmer.
Rules for identifiers:
o Can contain letters, digits, and underscores
o Cannot begin with a digit
o Must not be a keyword
o Are case-sensitive
4. What are Data Types in C?
Data types define the type of data a variable can hold. They help the compiler allocate
memory and interpret the data correctly.
Primary Data Types:
• int – integer (whole numbers)
• float – floating-point (decimals)
• double – double-precision floating-point
• char – character (single character)
Derived Data Types:
• Arrays, Pointers, Structures, Unions
Example:
int age = 25;
float salary = 45678.50;
char grade = 'A';
5. What are Constants in C?
A constant is a value that cannot be changed during the execution of a program.
Types of Constants:
• Integer Constants: 100, -10
• Floating Constants: 3.14, -0.001
• Character Constants: 'A', '5'
• String Constants: "Hello"
6. What are Variables in C?
A variable is a named location in memory used to store data. The value of a variable can
change during the execution of a program.
Example:
int age = 20; // 'age' is a variable
7. How to Declare Variables in C?
Variable declaration specifies the data type and name of the variable.
Syntax:
data_type variable_name;
Example:
int marks;
float percentage;
8. How to Assign Values to Variables?
Values can be assigned at the time of declaration or separately.
Example:
int x = 10; // Declaration with initialization
float y;
y = 5.5; // Assignment after declaration
9. How to Declare a Variable as a Constant?
Use the const keyword to declare a read-only variable.
Example:
const float PI = 3.14;
Once declared, you cannot change the value of PI.
10. What are Symbolic Constants?
Symbolic constants are defined using the #define preprocessor directive. They are replaced
by their values before compilation.
Example:
#define MAX 100
#define PI 3.14159
These are typically written in uppercase for clarity.
11. Sample Program: Using Constants, Variables, and Data Types
#include <stdio.h>
#define PI 3.14
int main() {
const int year = 2025; // Constant
int radius = 5; // Variable
float area;
area = PI * radius * radius; // Area of a circle
printf("Year: %d\n", year);
printf("Radius: %d\n", radius);
printf("Area = %.2f\n", area);
return 0;
}
Output:
Year: 2025
Radius: 5
Area = 78.50
12. What is the size of int and float typically?
Depends on system, but usually:
• int: 4 bytes
• float: 4 bytes
13. What is the size and range of int in C?
Typically:
• Size: 4 bytes
• Range: -2,147,483,648 to 2,147,483,647 (may vary by system)
14. What is the difference between float and double?
• float has 4 bytes, up to 6 decimal places
• double has 8 bytes, up to 15 decimal places
15. What is the output of this C program?
#include <stdio.h>
int main() {
const int a = 10;
// a = 20;
printf("%d", a);
return 0;
}
Output: 10