Que 1 : What do you mean by a program?
ANS: A program, in the context of computing and software development, refers to a set of instructions or code written in a programming language that is designed to perform a specific task or achieve a specific goal. Programs can be executed by a computer to carry out a wide range of tasks, from simple calculations to complex operations. Programs can be written by software developers using programming languages such as C, C++, Java, Python, or JavaScript, among many others. They can be used to create applications, software tools, games, websites, and other software products that serve various purposes and functions. Programs are fundamental building blocks of software and form the basis of modern computer applications and systems.
Que 2 : Explain different flowchart symbols
ANS :
Flowchart Symbol | Name | Description |
Process symbol | Also known as an “Action Symbol,” this shape represents a process, action, or function. It’s the most widely used symbol in flowcharting. | |
Start/End symbol | Also known as the “Terminator Symbol,” this symbol represents the start points, end points, and potential outcomes of a path. Often contains “Start” or “End” within the shape. | |
Input/Output symbol | Also referred to as the “Data Symbol,” this shape represents data that is available for input or output as well as representing resources used or generated. While the paper tape symbol also represents input/output, it is outdated and no longer in common use for flowchart diagramming. | |
Decision symbol | Indicates a question to be answered — usually yes/no or true/false. The flowchart path may then split off into different branches depending on the answer or consequences thereafter. | |
Arrow | Shows relationships between different shapes. |
Que 3 : Explain sum of 10 numbers with flowchart and algorithm.
ANS: Algorithm:
- Start
- Initialize a variable called “sum” to zero (sum = 0).
- Loop for 10 times (i = 1 to 10):
- a. Input a number from the user.
- b. Add the input number to the “sum” variable.
- End Loop
- Display the value of “sum” as the sum of 10 numbers.
- Stop
Que 4 : Explain “C is a middle level language”.
ANS:” C is a middle level language” means that C programming language strikes a balance between low-level and high-level languages in terms of abstraction and functionality. It provides a higher level of abstraction than low-level languages like assembly language, making it more human-readable and easier to program. At the same time, C retains low-level features such as direct memory access and bit-level operations, offering fine-grained control over hardware resources. C is efficient, portable, and widely used in system-level programming, embedded systems, and performance-critical applications, making it a versatile language for various types of applications.
Que 5 : Give the Basic structure of the C program.
ANS: Preprocessor Directives: These are statements that start with ‘#’ and provide instructions to the preprocessor.
Main Function: Every C program must have a main function, which serves as the entry point of the program.
Declarations: Declarations define variables and functions before they are used in the main function or other parts of the program.
Statements: Statements are the instructions that make up the logic of the program, including assignments, conditional statements, loops, and other programming constructs.
Comments: Comments provide explanations or documentation within the code, but they are not executed by the compiler.
#include<stdio.h>
#include<conio.h>
void main(){
//body
getch();
}
QUE 6 : Difference between Compiler and Interpreter.
ANS: Compilation vs. Interpretation: A compiler translates the entire source code into machine code before execution, while an interpreter translates and executes the source code line by line during runtime. Output: A compiler generates an executable file, while an interpreter produces output on-the-fly without creating a separate executable file. Performance: Compiled programs are generally faster, while interpreted programs may be slower due to repeated translation and execution at runtime.
Que 7: Explain following terms: 1) Keywords 2) Identifiers 3) Variables 4) Compiler 5) Operating System.
ANS: Keywords: Reserved words with special meanings in a programming language.
Identifiers: User-defined names for variables, functions, or entities in a program.
Variables: Named memory locations to store data during program execution.
Compiler: Software that translates source code into machine code.
Operating System: Software that manages and controls computer resources.
Que 8: What is a C token? Explain in detail.
ANS: Tokens in C can include keywords, identifiers, operators, literals (such as numeric or string literals), punctuators (such as braces, parentheses, commas, etc.), and comments. They are separated by whitespace characters (such as spaces, tabs, and line breaks) and are processed by the compiler in a sequential manner.
Tokens are used during the lexical analysis phase of the compilation process, where the source code is scanned and divided into meaningful units that can be further processed by the compiler
Que 9: Write a short note on basic data types that C language supports.
ANS: int: Represents integer values, which are whole numbers without any decimal point. The size of an int depends on the system architecture and can vary from 2 to 4 bytes.
float: Represents floating-point numbers, which are numbers with a decimal point. Float variables can store approximate values with limited precision and occupy 4 bytes of memory.
double: Represents double-precision floating-point numbers, which are numbers with a higher precision compared to float. Double variables occupy 8 bytes of memory.
char: Represents a single character or a small integer value. Char variables occupy 1 byte of memory.
void: Represents a lack of any data type. It is often used as a return type for functions that do not return any value.
Other data types: C also supports additional data types such as short, long, unsigned int, unsigned char, and others, which offer variations in size and signed/unsigned properties.
Que 10: Explain Implicit and Explicit type conversion with example.
ANS: Implicit type conversion, also known as type coercion, is an automatic conversion that occurs when a value of one data type is assigned to a variable of another data type without the programmer explicitly specifying the conversion. For example:
int num1 = 10;
float num2 = num1;
Explicit type conversion, also known as type casting, is a manual conversion that is explicitly specified by the programmer using casting operators. For example:
float num1 = 10.5;
int num2 = (int)num1;
Que 11: What is operator? Enlist all the operators used in C. Explain all in detail. ( write code for each operator except special and bitwise)
ANS: Arithmetic Operators: Addition (+): Performs addition operation. Subtraction (-): Performs subtraction operation. Multiplication (*): Performs multiplication operation. Division (/): Performs division operation. Modulus (%): Performs modulus (remainder) operation.
int a = 5;
int b = 3;
int sum = a + b; // addition
int diff = a - b; // subtraction
int product = a * b; // multiplication
int quotient = a / b; // division
int remainder = a % b; // modulus
Relational Operators:
- Greater than (>), Less than (<): Compares two values and returns true (1) if the condition is satisfied, otherwise false (0).
- Equal to (==), Not equal to (!=): Compares two values for equality and returns true (1) if the condition is satisfied, otherwise false (0).
- Greater than or equal to (>=), Less than or equal to (<=): Compares two values for equality and returns true (1) if the condition is satisfied, otherwise false (0).
int a = 5;
int b = 3;
int result1 = a > b; // greater than
int result2 = a < b; // less than
int result3 = a == b; // equal to
int result4 = a != b; // not equal to
int result5 = a >= b; // greater than or equal to
int result6 = a <= b; // less than or equal to
Logical Operators:
- Logical AND (&&), Logical OR (||): Perform logical operations on boolean expressions and return true (1) if the condition is satisfied, otherwise false (0).
- Logical NOT (!): Negates the value of a boolean expression.
int x = 5;
int y = 3;
int z = 7;
int result1 = (x > y) && (y < z); // logical AND
int result2 = (x > y) || (y > z); // logical OR
int result3 = !(x > y); // logical NOT
Assignment Operators:
- Assignment (=): Assigns a value to a variable.
- Addition and assignment (+=), Subtraction and assignment (-=): Performs the operation and assigns the result to a variable in a single step.
- Multiplication and assignment (*=), Division and assignment (/=): Performs the operation and assigns the result to a variable in a single step.
- Modulus and assignment (%=): Performs the operation and assigns the result to a variable in a single step.
int a = 5;
int b = 3;
a += b; // equivalent to a = a + b; (addition and assignment)
a -= b; // equivalent to a = a - b; (subtraction and assignment)
a *= b; // equivalent to a = a * b; (multiplication and assignment)
a /= b; // equivalent to a = a / b; (division and assignment)
a %= b; // equivalent to a = a % b; (modulus and assignment)
increment and Decrement Operators:
- Post-increment (i++), Post-decrement (i–): Increases or decreases the value of a variable by 1 after the operation is performed.
- Pre-increment (++i), Pre-decrement (–i): Increases or decreases the value of a variable
Que 12: Explain Precedence and associativity
ANS: Operator precedence determines the priority of operators in an expression, where higher precedence operators are evaluated before lower precedence operators.
Operator associativity determines the order in which operators of the same precedence are evaluated, either left-to-right (left associative) or right-to-left (right associative).
In C, operators have predefined precedence and associativity, but parentheses can be used to group expressions and enforce a specific evaluation order.
For example, in the expression “a + b * c”, multiplication (*) has higher precedence than addition (+), so “b * c” will be evaluated first.
Que 13: Explain nested if…else statement and switch case statement with example.
ANS: Nested if…else statement: Nested if…else statement is a construct in C where an if statement is nested inside another if or else block. It allows for multiple levels of conditional branching based on different conditions.
#include <stdio.h>
#include<conio.h>
void main() {
int x = 10,y = 5;
if (x > 0)
{
printf("x is positive.\n");
if (y > 0) {
printf("y is also positive.\n");
}
else {
printf("y is not positive.\n");
}
}
else {
printf("x is not positive.\n");
}
getch();
}
Switch case statement: Switch case statement is used for multi-way branching based on the value of a variable. It allows for efficient and concise handling of multiple cases.
#include <stdio.h>
#include<conio.h>
void main()
{
int day = 3;
switch (day)
{
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
default:
printf("Invalid day\n");
}
getch();
}
QUE 14: What is getch() and getchar() ?
ANS: getch() and getchar() are functions in C for reading input from the user. getch() is a non-standard function that reads a single character without echoing it to the screen or requiring the Enter key to be pressed, often used in Windows-based environments. getchar() is a standard function that reads a single character, echoes it to the screen, and requires the Enter key to be pressed.
Que 15: What is putch() and putchar() ?
ANS: putch() and putchar() are functions in C used for displaying output to the console. putch() is a non-standard function used in Windows-based environments to display a character without appending a newline character, while putchar() is a standard function that appends a newline character after displaying a character on the console.
Que 16: Explain different forms of if Statements with examples.
ANS: Simple “if” statement: Executes a single statement if a condition is true.
if (x > 0) {
printf("x is positive\n");
}
if-else” statement: Executes one set of statements if a condition is true and another set of statements if the condition is false.
if (x > 0) {
printf("x is positive\n");
}
else {
printf("x is non-positive\n");
}
if-else if” statement: Checks multiple conditions in sequence and executes the corresponding set of statements for the first true condition.
if (x > 0) {
printf("x is positive\n");
}
else if (x < 0) {
printf("x is negative\n");
}
else {
printf("x is zero\n");
}