Pps Answers
Pps Answers
Ans:- The main() function is the starting point of a program, where the computer begins executing
the code.
The main() function i.n C programming is the entry point of a program, where execution begins
Ans:-
Ans:-
Linking
Linking is the process of combining multiple object files into a single executable file. This process is
necessary to create a self-contained program. There are two types of linkers: static and
dynamic. Static linkers merge all the necessary object code and libraries into a single executable
file. Dynamic linkers allow the program to be loaded into memory at runtime and link to shared
libraries.
Definition section
A declaration establishes an association between a variable, function, or type and its attributes. It
also specifies where and when an identifier can be accessed
A variable is a named container for storing data in a program. The syntax for declaring a variable
depends on the programming language:
The syntax for declaring a variable in C is type variableName = value. For example, int myNum =
15 creates a variable named myNum of type int and assigns it the value 15.
Ans:- A compiler translates source code into machine code before a program runs, while an
interpreter translates code line-by-line as the code runs Part -A
Ans:-
A multi-dimensional array is an array with more than one level or dimension. For example, a 2D
array, or two-dimensional array, is an array of arrays, meaning it is a matrix of rows and columns
(think of a table). A 3D array adds another dimension, turning it into an array of arrays of arrays
Ans:-Strings are sequences of characters enclosed in double quotes, used for handling text and
varying in length. Characters, represented by single symbols in single quotes, are primitive data types
primarily used for storing and manipulating individual symbols.
dataType1 member1; dataType2 member2; The member variables, also known as fields,
and their data types
Example:-
struct MyStructure {
};
4.What are the advantages of loops? Loops are a fundamental concept in programming that have
many advantages, including:
Ans:-
Code reusability
Loops can save time and reduce errors by minimizing the number of lines of code.
Loops reduce repetition, which can lead to clearer and more effective code.
Dynamic programs
Loops allow developers to create dynamic programs that can efficiently perform repetitive tasks.
Loops can be used to traverse over the elements of data structures, such as arrays or linked lists.
If statement
A fundamental conditional statement that evaluates if a statement is true or false. If the statement is
true, the if statement runs. If the statement is false, the program skips to the next section.
If-else statement
Defines conditions for execution. If the if condition is true, the if statement executes. If the if
condition is false, the else statement executes.
Nested if statement
An if statement inside another if statement. This is used when a variable needs to be processed more
than once.
Switch statement
Evaluates an expression against multiple cases and executes one or more blocks of code based on
matching cases.
Ternary operator
Also known as the conditional operator, conditional expression, ternary if, or inline if (iif). It can be
used to replace if-else statements
Ans:-
A union is a user-defined data type that allows different data types to be stored in the same memory
location. The size of the union is determined by the size of its largest member.
Ans:-
Pointer to pointer: A pointer variable that holds the address of another pointer
Ans:
Pointers are used in self-referential structures to store the address of the next node, which allows for
iteration through data structures
Ans:-
Direct memory access: Pointers allow you to directly access and manipulate memory
locations, which can improve performance. This is especially useful when working with large
data structures or performing low-level operations.
Dynamic memory allocation: Pointers can be used to take advantage of dynamic memory
allocation.
PART-B
Case sensitivity: Identifiers are case-sensitive, so "myVar" and "myvar" are different
identifiers.
Characters: Identifiers can contain letters, digits, and underscores, but no other special
characters.
Uniqueness: Each identifier must have a unique name within the scope it is defined in.
ANS:-
#include <stdio.h>
void main()
{
int a;
float b;
char c;
double d;
Ans:-
Precedence, associativity, and order of evaluation are concepts that determine how operators and
operands are grouped and evaluated in expressions:
Precedence: The priority for grouping operators with operands. Operators with higher
precedence are evaluated first.
Associativity: The order for grouping operands with operators that have the same
precedence. Associativity can be left-to-right or right-to-left.
Understanding these concepts is important for writing efficient and correct code. Parentheses can be
used to override precedence and associativity
C: In C, precedence determines the order in which operators are evaluated, and associativity
determines the order in which operators with the same precedence are evaluated.
4. Write a C program to find the maximum of two numbers using a ternary operator.
ANS:-
#include <stdio.h>
int main() {
int a,b;
scanf("%d%d", &a,&b);
return 0;
#include<stdio.h>
int main()
int x, y;
scanf("%d%d",&x,&y);
x=x+y;
y=x-y;
x=x-y;
return 0;
7.Explain about the various steps involved in creating and running a C program.
Ans-
Writing the code: Open a text editor or IDE and create a new file with a .C extension.
Compilation: The compilation process converts the source code into machine code. This
process includes four stages:
o Compilation: The preprocessed source code is converted to machine code, and the
compiler checks for errors.
Execution: The operating system loads the executable file into memory, and the program
begins to execute
8.What is meant by Operator? List the types of Operators and explain any four operators with a C
program
Ans:- An operator is a fundamental tool or sign used to perform mathematical and logical operations
in programming languages. Here are some types of operators in C and their examples:
Arithmetic operators
Relational operators
Also known as Comparison Operators, these compare the values of the two operands. The result of
the comparison is either true or false. Examples of relational operators include:
>: Checks if the value of left operand is greater than the value of right operand
<: Checks if the value of left operand is less than the value of right operand
9.Define type casting and explain in detail about implicit and explicit type casting with example
programs?
Type casting is the process of converting a variable from one data type to another. There are two
types of type casting: implicit and explicit:
Also known as widening conversion, this is when the compiler automatically converts a smaller type
to a larger type size. This happens when there is no loss of data.
This is when a programmer manually converts a larger type to a smaller type size. This is used when
there is a possibility of data loss
In C, the compiler can automatically change one data type to another based on the program's
requirements. For example, if an integer (int) value is assigned to a float variable (floating point), the
compiler will automatically convert the int value into a float value
#include<stdio.h>
void main()
float result;
#include<stdio.h>
int main()
int i=3;
float b;
b=i;
return 0;
Ans:-
#include <stdio.h>
void main( )
{
int a, b, c;
if(a > b)
if(a > c)
else
else
if(b > c)
else
}.
2. Write a C program to find the sum of digits of a given number
Ans:-
#include <stdio.h>
void main()
scanf("%d", &n);
while (n > 0)
r = n % 10;
n = n/10;
Ans:
#include<stdio.h>
main()
int a[50];
int n,i,max;
scanf("%d",&n);
printf("enter the number of elements");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
max=a[0];
for(i=1;i<n;i++)
if(a[i]>max)
max=a[i];
printf("max=%d",max);
4.Write in detail about any five string handling functions with examples
Ans:
#include<stdio.h>
#include<string.h>
void main ()
char str1[50]="Hello";
char str2[50]="World";
char str3[50];
int len;
strcpy(str3, str1);
len=strlen(str1);
printf("strlen(str1) : %d\n",len);
5.Explain in detail about declaring two dimensional arrays, reading elements and displaying the
elements of it.
Ans:-
#include <stdio.h>
int main() {
int n = 29;
int cnt = 0;
// it is not prime
if (n <= 1)
else {
// by n
if (n % i == 0)
cnt++;
if (cnt > 2)
// else it is prime
else
return 0;
7 Explain in detail about pre- test/Entry Controlled and post- test/Exit controlled loops with
example programs.
Ans:-
In looping, the set statement executes until the condition becomes false.
1. Entry Controlled loops: In this type of loops the test condition is tested before entering the
loop body. For Loop and While Loop are entry-controlled loops.
2. Exit Controlled Loops: In this type of loops the test condition is tested or evaluated at the
end of loop body. Therefore, the loop body will execute atleast once, irrespective of whether
the test condition is true or false. do – while loop is exit-controlled loop.
Types of Loops
1. while loop
2. for loop
3. do while loop
while loop
Syntax :
while(condition)
statements;
It is completed in 3 steps.
In while loop, condition is executed first, If the condition is true the body loop will executed , again
check the condition if true the body loop will be executed this process will be continue until the
condition false then the loop is terminated,
#include<stdio.h>
void main( )
int x;
x = 1;
x++;
Output:
1 2 3 4 5 6 7 8 9 10
do…while loop
Syntax:
do{
statement (s);
} while(condition);
#include <stdio.h>
int main()
int j=0;
do
j++;
} while (j<=3);
return 0;
Output
4. Then it evaluates the increment/decrement again check the condition follows from step 2.
#include<stdio.h>
void main()
int n, i, sum=0;
scanf("%d",&n);
sum = sum + i;
Output
When we need to execute a block of statements only when a given condition is true then we
use decision making statement
1. if statement
2. switch statement
1. if statement
1. Simple if
2. if..else,
3. nested if..else
4. else..if. ladder
simple if statement:
if condition is "false" then statement inside block will skipped i.e. not executed, statement outside
block executed.
if(expression)
Statement_inside;
Statement_outside;
Example 1:
#include<stdio.h>
void main()
int x =20;
int y =22;
if(x<y)
Example 2:
#include <stdio.h>
void main()
int n;
scanf("%d", &n);
printf("End of statement\n");
output
Enter an integer: -2
End of statement
2. if...else statement
Syntax:
if(expression)
statement block1;
else
statement block2;
}
If the expression is true, the statement-block1 is executed, else statement-block1 is skipped and
statement-block2 is executed.
Example 1: Write a program to check whether the given number is odd or even.
#include<stdio.h>
void main()
int n;
if(n%2 == 0)
else
Output:
60 is Even Number
End of program
Syntax:
if( expression1 )
if( expression2 )
statement block1;
else
statement block2;
}
else
statement block3;
if expression1 is false then statement-block3 will be executed, otherwise the execution continues and
enters inside the first if to perform the check for the next if block, where if expression 2 is true the
statement-block1 is executed otherwise statement-block2 is executed.
void main( )
int a, b, c;
if(a > b)
if(a > c)
else
else
if(b > c)
else
}// main
Output:
Enter 3 numbers...:
12
12 is the greatest
3. else if ladder
if(expression1)
statement block1;
elseif(expression2)
statement block2;
elseif(expression3 )
statement block3;
}
else
default statement;
Statement_Next;The expression is tested from the top (of the ladder) downwards. As soon as a true
condition is found, the statement associated with it is executed.
Conditions:
Otherwise fail.
#include<stdio.h>
void main()
int per;
scanf("%d",&per);
if(per>=75)
printf("Division = Distinction\n");
printf("Division = First\n");
printf("Division = Second\n");
printf("Division = Third\n");
else
}
Output:
Division = First
End of program
#include<stdio.h>
void main()
int a[10][10],b[10][10],c[10][10];
int r1,c1,r2,c2;
int i,j,k;
int sum=0;
scanf("%d%d",&r1,&c1);
scanf("%d%d",&r2,&c2);
if(c1==r2)
printf("enter a elements");
for(i=0;i<r1;i++)
{ for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
printf("enter b elements\n");
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
scanf("%d",&b[i][j]);
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
{ sum=0;
for(k=0;k<c1;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
{
printf("%d\t",c[i][j]);
printf("\n");
else
1.Define Pointer? What are the types of Pointers? Explain with examples.
The pointer in C language is a variable which stores the address of another variable.
This variable can be of type int, char, array, function, or any other pointer.
The size of the pointer depends on the architecture. However, in 32-bit architecture the size
of a pointer is 2 byte, in 64-bit architecture the size of a pointer is 4 byte.
Syntax :
data_type *var_name;
where
Where, * is used to denote that “p” is pointer variable and not a normal variable.
Consider the following example to define a pointer which stores the address of an integer.
int n = 10;
int* p = &n;
// Variable p of type pointer is pointing to the address of the variable n of type integer.
Pointer Example
An example of using pointers to print the address and value is given below.
int n=50;
int *p;
p=& n;
TYPES OF POINTERS
1. NULL Pointer
A pointer that is not assigned any value but NULL is known as the NULL pointer.
If you don't have any address to be specified in the pointer at the time of declaration, you
can assign NULL value. It will provide a better approach.
#include <stdio.h>
int main()
{
// Null Pointer
return 0;
Output:
2. Wild Pointer
A pointer which has not been initialized to anything (not even NULL) is known as wild pointer.
Program:
int main()
int x = 10;
p = &x;
return 0;
Note: NULL vs Void Pointer – Null pointer is a value, while void pointer is a type
3. Dangling Pointers in C
Dangling pointer is a pointer pointing to a memory location that has been free (or deleted).
4. Void pointer
Void pointer is a pointer which is not associate with any data types.
It points to some data location in storage means points to the address of variables. It is also
called general purpose/universal pointer.
Syntax:
void *variable_name;
Program:
#include<stdlib.h>
void main()
int x = 4;
float y = 5.5;
ptr = &x;
Output:
Integer variable is = 4
void main()
int number=50;
p2=&p;
Output:
void main()
int i;
printf("%d\n", *p);
p++;
#include <stdio.h>
struct person
char name[30];
int age;
float weight;
};
void main()
scanf("%s", &p1->name);
scanf("%f", &p1->weight);
Output:
Enter age: 21
Enter weight:61.5
Name: Amit
Age: 21
weight:61.5
Definition:
Self referential a structure definition which includes/contain at least one member that is a pointer to
the structure variable of same structure is called self referential structure
Syntax:
struct name
member 1;
member 2;
...
};
Example:
Self-referential structures are very useful in applications that involve linked data structures,
such as lists and trees.
Static data structure such as array where the number of elements that can be inserted in the
array is limited by the size of the array.
Self-referential structure can dynamically be expanded or contracted.
Operations like insertion or deletion of nodes in a self- referential structure involve simple
and straight forward alteration of pointers.
A linear linked list is a chain of structures where each node points to the next node to create a list.
To keep track of the starting node's address a dedicated pointer (referred as start pointer) is used.
The end of the list is indicated by a NULL pointer. In order to create a linked list of integers, we define
each of its element (referred as node) using the following declaration.
struct node_type
int data;
};