Q.
1 Explain different data types in C
In C programming, data types tell the computer what kind of data a variable will
store, such as numbers, characters, or decimals.
C has the following main types of data:
1. Basic Data Types : These are the most commonly used:
• int: Used to store whole numbers.
Example: int age = 20;
• float: Used to store decimal numbers (less precise).
Example: float price = 99.99;
• double: Used for more precise decimal numbers.
Example: double pi = 3.14159;
• char: Used to store a single character.
Example: char grade = 'A';
• void: Means "nothing" or "no value." Used in functions that return nothing.
2. Derived Data Types : These are built using basic types:
• Arrays: Store multiple values of the same type.
Example: int marks[5];
• Pointers: Store the memory address of another variable.
Example: int *ptr;
• Functions: Return and use different data types.
3. User-Defined Data Types : Created by the programmer:
• struct: Combines different types of variables
• union: Similar to struct, but uses shared memory.
• enum: Used to name a set of integer values.
Q.2 What are TERNARY OPERATOR AND GIVE ITS ONE EXAMPLE
Ternary Operator in C :The ternary operator is a short way to write
an if-else statement.
It uses the ? (question mark) and : (colon) symbols.
Syntax: condition ? expression1 : expression2;
• If condition is true, it executes expression1
• If condition is false, it executes expression2
Example:
int a = 10, b = 20;
int max;
max = (a > b) ? a : b;
printf("The maximum is %d", max);
Output: The maximum is 20
Explanation:
• Here, (a > b) is checked.
• If true, a is assigned to max; otherwise b is assigned.
• Since a = 10 and b = 20, the condition is false, so max = b
= 20.
Q.3 Component of C
Component Description
Smallest units in a program: keywords, identifiers,
1. Tokens
constants, operators, etc.
2. Variables Used to store data. Must be declared before use.
Define the type of data a variable can hold (e.g.,
3. Data Types
int, float, char).
Symbols used to perform operations (e.g., +, -, ==,
4. Operators
&&).
Blocks of code that perform specific tasks (e.g.,
5. Functions
main(), printf()).
6. Control Control the flow of the program (if, for, while,
Statements switch).
7. Preprocessor Special instructions processed before compilation
Directives (e.g., #include, #define).
Q.4 Structure of c with suitable example
Section Purpose
1. Header Files / Preprocessor
Includes libraries (e.g., #include <stdio.h>)
Directives
2. Global Declarations Variables or functions declared outside main()
3. main() Function Starting point of the program
4. Variable Declarations Declaring variables used in the program
5. Body of the Program Contains logic, calculations, loops, etc.
Ends the program and returns a value to the OS
6. Return Statement
(return 0;)
EXP : #include <stdio.h> // 1. Header file
// 2. Global declarations (optional)
int main() // 3. Main function {
int a = 5, b = 10; // 4. Variable declarations
int sum;
sum = a + b; // 5. Logic / body
printf("Sum = %d", sum);
return 0; // 6. Return statement
}
Q.5 define algorithm and state property of it
Definition of Algorithm: : An algorithm is a step-by-step procedure or set
of instructions used to solve a problem or perform a task in a finite
amount of time. In simple words, it's like a recipe that tells a computer
exactly what to do, step by step.
Properties of a Good Algorithm:
Property Description
1. Input Takes zero or more inputs
2. Output Produces at least one output
3. Definiteness Each step is clearly and exactly defined
The algorithm must complete in a finite number of
4. Finiteness
steps
5. Effectiveness Every step must be simple and possible to perform
The algorithm should work for a range of inputs, not
6. Generality
just one case
Q.6 develop a program in c to perform addition, multiplication of two number
by using arithmetic operator
#include <stdio.h>
int main() {
int num1, num2, sum, product;
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
sum = num1 + num2; // Addition
product = num1 * num2; // Multiplication
printf("Sum = %d\n", sum);
printf("Product = %d\n", product);
return 0;
OUTPUT : Enter first number: 4 ,Enter second number: 5 , Sum = 9 , Product = 20
Q.7 differentiate between compiler and interpreter
Point Compiler Interpreter
Translates the whole
Translates the program
Definition program at once into
line-by-line
machine code
Slower, as it translates
Faster execution after
Speed and executes one line
compilation
at a time
Error Shows all errors together Shows one error at a
Detection after compiling time during execution
Creates a separate Does not create an
Output
executable file (e.g., .exe) executable file
Example C, C++, Java (compiled to
Python, JavaScript, PHP
Languages bytecode)
Execution More, due to line-by-
Less, since it's precompiled
Time line execution
Q.8 Define operating system
An Operating System (OS) is a special type of software that acts as an
interface between the user and the computer hardware. It manages all
the hardware and software resources of a computer and provides services
to the programs. In simple words An Operating System is the main program
that controls the computer and helps you run other programs easily.
Functions of an Operating System:
• Manages hardware like CPU, memory, and devices (printer, keyboard,
etc.)
• Manages software and runs programs
• Provides a user interface (like Windows or Linux desktop)
• Handles file management, security, and task scheduling
Example of Operating Systems:
• Windows
• Linux
• macOS
• Android
Q.9 write down about precedence and associavity
1. Operator Precedence (Priority of Operators)
• In programming, an expression can have many operators (like
+, -, *, /, etc.).
• Precedence tells us which operator will be evaluated first in
an expression that contains multiple different operators.
• Operators with higher precedence are evaluated before
operators with lower precedence.
2. Operator Associativity (Order of Evaluation for Same
Precedence)
• Sometimes, an expression contains two or more operators
with the same precedence.
• Associativity defines whether these operators are
evaluated left to right or right to left.
• Most operators in C are left-to-right associative.
• Some operators like assignment (=), unary operators, and the
conditional ternary operator (?:) are right-to-left associative.
Q.10 list out various input and output statement in c
Common Input Statements:
Statement Description
scanf() Reads formatted input from the keyboard
getchar() Reads a single character from input
gets() (unsafe) Reads a string from input (unsafe, avoid using)
fgets() Reads a string safely with size limit
Common Output Statements:
Statement Description
printf() Prints formatted output to the screen
putchar() Prints a single character to the screen
puts() Prints a string followed by a new line