Reduced
Reduced
Ph: 03172031442
Computer
Solved topics according to reduced syllabus (2025)
Characteristics of C Language
The C language became popular because of its powerful features. Some important characteristics of C are:
1. Simple and Structured
• C follows a structured programming approach, which means a program is divided into small functions,
making it easy to read and modify.
2. Portable (Machine-Independent)
• A program written in C can run on different computer systems with minimal changes. This feature makes C
highly portable and useful for developing software that works on multiple platforms.
3. Fast and Efficient
• C is a low-level language, meaning it interacts closely with the computer hardware. This makes it faster than
other high-level languages like Python or Java.
4. Supports Low-Level Programming
• Unlike many modern programming languages, C allows direct memory access and hardware control, which
is why it is used for system programming.
5. Rich Set of Operators and Functions
• C has a variety of built-in operators (arithmetic, logical, relational, etc.) and library functions, making
programming easier.
6. Extensible
• New features and libraries can be added to C to extend its capabilities.
History of C Language
The development of the C language can be traced back to the 1960s and 1970s. It evolved over time and became
the foundation of many modern programming languages.
Languages Before C
Before C, there were two main programming languages:
BCPL (Basic Combined Programming Language) – Developed in 1966 by Martin Richards, it was used for writing
system software.
B Language – Developed by Ken Thompson in 1970, this was a simpler version of BCPL but lacked some
important features.
Since these languages were not very powerful, a better language was needed. This led to the development of C in
1972 by Dennis Ritchie.
Syntax
Medium Simple Medium
Complexity
Solutions:
Q1: Write a detailed note on the history of the C language.
Introduction
C is a general-purpose, structured, and procedural programming language that was developed in 1972. It
became one of the most widely used programming languages and served as the foundation for many
modern languages like C++, Java, and Python.
Who Developed C?
C was developed by Dennis Ritchie at Bell Laboratories (Bell Labs) in 1972. It was created to overcome the
limitations of previous languages like B and BCPL and to develop the UNIX operating system.
Why Was C Created?
Before C, programmers used languages like Assembly, BCPL, and B, but these languages had limitations:
1. Assembly language was difficult to use – Programs were written in machine-level instructions,
making them complex.
2. BCPL and B had fewer features – They lacked data types and other important programming tools.
3. Needed a powerful system programming language – UNIX was being developed at Bell Labs, and a
better language was required for writing it.
To solve these issues, Dennis Ritchie developed C, which was more efficient, structured, and easy to use.
Evolution of C Language
Year Version Features
1972 C (Original) Created by Dennis Ritchie for UNIX.
1978 K&R C First book on C published by Kernighan & Ritchie.
1989 ANSI C (C89) Standardized version for compatibility.
1999 C99 Introduced inline functions, variable-length arrays.
2011 C11 Added multithreading and security improvements.
2018 C17 Minor updates and performance improvements.
Conclusion
C is one of the most influential programming languages in history. It revolutionized system programming
and software development and is still used today in various applications, including operating systems,
embedded systems, and database management systems.
1) Identifiers:
Identifiers are name given to various program elements, such as variables, functions and arrays. Following
rule must be observed while constructing identifiers.
1: An identifier must start with a letter or (rarely) an underscore (_).
2: An identifier can contain letters, digits, or underscore. (_).
3: An identifier cannot contain blanks, commas or any other special characters.
4: An identifier cannot consist of more than 31 characters.
5: An identifier must confirm to case sensitivity (C differentiates between uppercase and lowercase
alphabetical characters). For example, the identifier MAX is not same as the identifier max.
2) Variables:
A variable is a programming- defined identifier whose value can change during the execution of the
program. All variables must have a name and a data type. C supports most of the common data types for
variables – integer, float (real), and character.
Rules For constructing Variable Names:
1: The first character in the variable name must be an alphabet.
2: No commas or blanks are allowed within a variable name.
3: No special symbol other than an underscore (as in tax_rate) can be used in a variable name.
Declaration of variable:
A declaration associates a group of variables with a specific data type. A declaration consists of a data type,
followed by one or more variable names, ending with a semicolon.
Example:
{
Int num;
float tax_rate;
This creates an int variable name num, and a float variable called tax_rate.
Initialization of variable:
Variable initialization in C means assigning an initial value to a variable at the time of declaration. This
prevents the variable from holding a garbage value.
Example:
int num = 10;
float tax_rate = 5.5;
char grade = 'A';
double price = 99.99;
long population = 8000000;
Each variable is declared and initialized with a value at the same time.
v) Symbolic Constant:
A symbolic constant is a programmer-defined identifier that is replaced with a sequence of characters
called text. The replacement text may represent a numeric constant, a character constant or a string
constant.
Example: const float PI=3.14159; , const int YEAR_LENGTH = 12;, const char ANSWER = ‘Y’;
Initialization Of pointers:
Pointer initialization is the process of assigning a valid memory address to a pointer variable. A pointer
must be initialized before it is used to avoid storing garbage values, which can lead to unexpected program
behavior or crashes. The memory address assigned to a pointer comes from a normal variable using the
address-of (&) operator.
Example: #include <stdio.h>
int main() {
int num = 25; // Normal integer variable
int *ptr = # // Pointer storing address of num
return 0;
}
Explanation:
• ptr is a pointer that stores the address of num.
• The dereferencing operator (*ptr) is used to access the value stored at that memory location.
• Proper initialization ensures the pointer does not hold a random or invalid memory address,
preventing errors.
This concept is crucial for efficient memory management and dynamic programming in C.
Deceleration of Pointers:
Pointer declaration in C means creating a pointer variable that can store the memory address of another
variable. A pointer is declared using the * (asterisk) symbol before the pointer name, along with its data
type, which specifies the type of variable the pointer will point to.
data_type specifies the type of variable the pointer will point to (int, float, char, etc.).
*pointer_name declares the variable as a pointer.
Example: #include <stdio.h>
int main() {
int *ptr; // Pointer declaration (stores address of an int variable)
float *fptr; // Pointer declaration (stores address of a float variable)
return 0;
}
Explanation:
• int *ptr; declares a pointer ptr that can store the address of an integer variable.
• float *fptr; declares a pointer fptr that can store the address of a float variable.
• The asterisk (*) does not mean multiplication here; it signifies that the variable is a pointer.
Declaring pointers is essential for dynamic memory allocation, efficient memory handling, and advanced
programming techniques in C.
Classification of Operator:
Basically C language has 45 types of different operators and here are some of most common types include:
1: Arithmetic Operator
2: Assignment Operator
3: Relational Operator
4: Increment Operator
5: Conditional Operator
6: Increment Operator
7: Decrement Operator
8: Address Operator
9: Logical/ Boolean Operator
i) Arithmetic Operators:
Arithmetic operators are used to perform mathematical calculation. An arithmetic expression is made up
of variable, constant, a combination of both or a function call, connected by arithmetic operators.
Following list provide the detail about arithmetic operators.
Operator Operation Example
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b
% Remainder after integer division a%b
C offers a standard, minimal set of basic types. Sometimes these are called “primitive” type. A lot of
complex data structures can be developed from these basic data types. In C, data types define the type of
data a variable can store. The size of each data type depends on the compiler and system architecture
(usually 32-bit or 64-bit). The C language defines 4 fundamental data types.
*Character (char)
*Integer (int)
*Floating-point (float)
*Double floating-point (double)
These data types are declared using keywords char, int, float and double respectively. Typical memory
requirements of the basic data types are given below.
Functions:
A function is a block of instructions that together perform a specific task. Every C program has at least one
function, main (). You can also write your own functions and use them just as you use functions in a C
library. When your program starts, main () is called automatically and it is always executed first.
Classification of functions:
Functions are of two types, these are:
1)Built-in-function/ Library function/ Predefine function/ System define functions.
2) User defined function
2) Function Definition:
A function definition in C provides the actual implementation of a function that was declared earlier. It
includes the function header and body, where the logic is written. The function definition is the function
itself. The general structure of the function definition is:
Syntax: type function _ name (type argument -1, type argument -2, …)
{
Body of function
}
The function definition has two parts:
1) Function Header 2) Body of Functions
i) Function Header:
The function begins with a header which is exactly same as the function prototype except it must not be
terminated with semicolon (;). Header specifies the name of the function.
3) Function Calling:
A user defined function is called from the main program simple by using its name, including the
parentheses which follow the name. The parentheses are necessary so the compiler knows you are
referring to a function and not a variable that you forgot to declare.
void greet() {
printf("Hello, Welcome!\n");
}
int main() {
greet(); // Function call
return 0;
}
2) Function with No Arguments but Returns a Value:
The second function returns and integer value and does not accept any arguments. OR
Takes no parameters but returns a value.
Useful when a function generates or retrieves a value without external input.
Example:
#include <stdio.h>
int getNumber() {
return 25;
}
int main() {
int num = getNumber();
printf("Returned Number: %d\n", num);
return 0;
}
3) Function with Arguments but No Return Value:
The third function return no value but it accepts an argument x of the type integer. OR
Accepts parameters but does not return a value.
Used when a function performs an operation based on given input but doesn’t need to return anything.
Example:
#include <stdio.h>
int main() {
int sum = add(5, 7);
printf("Sum: %d\n", sum);
return 0;
}
Example:
#include <stdio.h> // Header files
// Global Declaration
int globalVar = 10;
// Main Function
int main() {
int localVar = 5; // Variable declaration
printf("Hello, World!\n");
display(); // Function call
return 0;
}
// User-defined Function
void display() {
printf("This is a user-defined function.\n");
}
Block of a C program:
Block Description
1. Preprocessor Directives #include<stdio.h> – Includes libraries for built-in functions.
2. Global Declarations Global variables/constants declared before main().
3. Function Declaration Declares user-defined functions before defining them.
4. main () Function The starting point of execution.
5. Variable Declaration Declares variables inside main() or functions.
6. Statements & Expressions Logical and arithmetic operations inside functions.
7. User-Defined Functions Functions created by the user for modular programming.
C preprocessor directives:
Preprocessor directives ate actually the instructions to the compiler itself. They are not translated but are
operated directly by the compiler. Note that preprocessor statements begin with a #symbol, and are not
terminated by a semicolon. Traditionally preprocessor statements are listed at the beginning of the source
file. They are also termed as macros.
The most common preprocessor directives are:
1) Include directives 2) Define directives
1) Include directives:
The include directive is used to include files. Like as we include header files in the beginning of the program
using #include directive e.g.
#include<stdio.h> #include<conio.h>
i)include<stdio.h>:
The #include<stdio.h> directive in C library is used to include the standard output library. Which provides
function like printf () and scanf () for input and output operations.
ii)#include<conio.h>:
The #include <conio.h> header file in C (short for Console Input/Output) is used to handle console-related
functions like clearing the screen, getting character input without pressing Enter, and more.
2) Define directives:
It is used to assign names to different constants or statements which are to be used repeatedly in a
program. These defined values or statement can be used by main or in the user defined functions as well.
i) Defining a constant:
For example,
#define PI3.1415687
#define g9.8
i) Defining a statement:
For example,
#define TRUE 1
i) Defining a mathematical expression:
For example,
#define floatingpointno float
2. Source Code in C
Source Code is the set of instructions written by the programmer in a file with a .c extension before
compilation.
It is written in human-readable form using C syntax.
It needs to be compiled into machine code using a C compiler (e.g., GCC, Turbo C).
Example:
#include <stdio.h>
void greet () {
printf ("Hello, Welcome! \n");
}
int main () {
greet (); // Calling user-defined function
return 0;
}
Here, the source code contains:
• A preprocessor directive (#include <stdio.h>)
• A function definition (greet ())
• The main function (main ())
• Curly braces {} to define function bodies.
Initialization
Test No
Condition
?
Yes
Statement(s)
Increment/
Decrement
Flowchart format of for loop
2) The While loop:
The while loop is used to repeat a section of code an unknown number of times until a specific condition is
met. OR
A while loop in C is a pre-tested loop that allows a block of code to execute repeatedly as long as the given
condition remains true.
Syntax of while loop:
while(condition) {
// Code to be executed
}
Condition → The loop runs as long as this condition is true.
Body → The block of code inside {} executes repeatedly.
Update Statement → The loop variable must be updated inside the loop; otherwise, it may become an
infinite loop.
Test No
Condition
?
Yes
Statement(s)
Statement(s)
Test Yes
Condition
?
No
Selection/Decision making structures (If, If-else, else-if, and switch -case with syntax):
In C programming, selection (or decision-making) statements allow the program to execute different code
blocks based on certain conditions. These statements control the flow of execution and decide which
statements should be executed.
There are three types of decision-making structures in C:
“If statement, “If-else” statement, “else-if” statement “switch case” statement
1) If Statement:
The if statement test a particular condition. Whenever that condition evaluates as true, an action is
performed-but if it is not true. Then the action is skipped and control transfer to the next step of the
program.
Syntax:
if(condition) {
statements; // Code to execute if the condition is true
}
Flowchart:
Test No
Condition
?
Yes
Statement(s)
If statement Flowchart
2) If-else statement:
The if selection structures perform an indicated action only when the condition is true, otherwise the
action is skipped. Whereas, if-else selection structure performs certain action when the condition is true
and some different action when the condition is false.
Syntax:
if(condition) {
statements;// Code to execute if the condition is true
} else {
Statements; // Code to execute if the condition is false
}
Flowchart:
Test No
Condition
?
Yes
Statement 2
Statement 1
3) else-if statement:
When multiple conditions need to be checked one by one, we use the else if ladder.
Syntax:
if(condition1) {
Statement 1; // Code to execute if condition1 is true
} else if(condition2) {
Statement 2; // Code to execute if condition2 is true
} else if(condition3) {
Statement 3; // Code to execute if condition3 is true
} else {
Statement 4; // Code to execute if none of the conditions are true
}
4) Switch Case statement:
The switch-case statement is used when a variable needs to be compared with multiple values. Instead of
using multiple if-else conditions, we can use switch-case, which makes the code more readable.
Syntax:
switch(expression) {
case value1:
statement; // Code to execute if expression == value1
break;
case value2:
statement; // Code to execute if expression == value2
break;
case value3:
statement; // Code to execute if expression == value3
break;
default:
statement; // Code to execute if none of the cases match
}
Flowchart:
Yes
Case Case 1 statement break
1
Yes
Case Case 2 statement break
2
Yes
Case Case n statement break
n
Default statement
Arrays:
An array is a collection of variables of the same type that are collectively referred to by the common name.
In C all arrays are stores respectively in successive or memory locations. We can manipulate array data
type collectively or individually depending on the requirements of each particular application. An individua
variable in the array is called an array element. OR
In C, arrays are fundamental data structures used to store and manipulate collections of elements.
Types of arrays:
One-Dimensional Arrays (Linear array)
Two-Dimensional Arrays (Matrix) (2D arrays)
Multi-Dimensional Arrays (Higher-order arrays) (3D or 4D array)
Uses of 2D arrays:
Used in mathematical matrices and graphs.
Helpful in storing tables, spreadsheets, and images (pixels).
Widely used in games for grids (chessboard, tic-tac-toe).
Declaration of variable:
Declaration of more than one array can be made in one statement as given below. OR
An array in C is a collection of elements of the same data type, stored in contiguous memory locations.
Int temps [5], index [7];
Float fact, m, total;
Syntax:
data_type array_ name[size];
Array initialisation:
Array initialization means assigning values to an array at the time of declaration or later in the program.
We can initialize a simple variable when we declare it as:
Int total =0;
Like this we can also initialise an array at the time of its declaration. Let temps is one-dimensional int array
having 5 elements, can be declared and initialized as:
Int temps [5] = {53, 85,29,19,63};
Syntax:
data_type array_ name[size] = {value1, value2, value3, ...};
Definition of String in C
A string in C is a sequence of characters stored in a character array, ending with a null character (\0) to
indicate the end of the string. Unlike other programming languages, C does not have a built-in string data
type, so strings are managed using character arrays. The null character (\0) helps differentiate a string from
a regular character array. Strings are commonly used for storing and manipulating text in C programs.
Strings gets(), getc(), puts(), putc(), strlen(), strcpy(), strmcp(), strcat(), (with
syntax) :
Gets ():
Reads a full string (including spaces) from standard input, but it's unsafe due to buffer overflow risks.
Syntax:
gets(str);
Puts ():
Prints a string to standard output and automatically adds a newline (\n).
Syntax:
puts(str);
Putc ():
Prints a single character to output (useful for file handling).
Syntax:
putc(ch, stdout);
Strlen ():
Returns the length of a string, excluding the null terminator \0.
Syntax:
strlen(str);
Strcpy ():
Copies the contents of one string (src) to another (dest).
Syntax:
strcpy(dest, src;
Strcmp ():
Compares two strings and returns 0 if equal, <0 if str1 is smaller, and >0 if str1 is greater.
Syntax:
strcmp(str1, str2);
Strcat ():
Appends (concatenates) src to the end of dest, modifying dest.
Syntax:
strcat(dest, src);
Getc ():
Reads a single character from input (can be used for file handling).
Syntax:
getc(stdin);