You are on page 1of 7

Part A

Answer any 10 questions

1. Define system software


System software is a type of computer program that is designed to run a
computer's hardware and application programs.
2. What is debugging
Debugging is the process of finding and fixing errors or bugs in the source
code of any software. When software does not work as expected, computer
programmers study the code to determine why any errors occurred.
3. What is decrement and incriment operators in C
‘++’ ‘—‘
4. What is the use of getchar() and putchar() functions
putchar() function is a file handling function in C programming language
which is used to write a character on standard output/screen. getchar()
function is used to get/read a character from keyboard input.
5. Give the syntax for while statement
while(condition)
{
statement(s);
}
6. Mention different jump statements in C
The three Jump Statement in C available in C are the break, continue, and
goto statements. The break statement is used to immediately exit a loop or
switch statement, while the continue statement is used to skip the current
iteration of a loop and move on to the next one
7. define 2 dimensional array
A two-dimensional array, also known as a 2D array, is a collection of data
elements arranged in a grid-like structure with rows and columns. Each
element in the array is referred to as a cell and can be accessed by its row
and column indices/indexes.
8. what are strings ?mentioned string built in functions
In C programming, a string is a sequence of characters terminated with a
null character \0 .
strcat() It concatenates two strings and returns the concatenated string.
strncat() It concatenates n characters of one string to another string.
strcpy() It copies one string into another.
strncpy() It copies the first n characters of one string into another.

9. What is recursion ?
 Recursion is a process by which a function calls itself directly or indirectly.
10.differentiate between structures and unions
A Structure does not have a shared location for all of its members. It makes
the size of a Structure to be greater than or equal to the sum of the size of its
data members. A Union does not have a separate location for every member
in it.
11.mention the advantages of pointers
Pointers in C programming are helpful to access a memory location.
Pointers are an effective way to access the array structure elements.
Pointers are used for the allocation of dynamic memory and the distribution.
12.what are files? explain the modes of opening your file
r - open a file in read mode. w - opens or create a text file in write mode. a -
opens a file in append mode. r+ - opens a file in both read and write mode
Part B answer any 6 questions

13.Explain programme development lifecycle


Program development life cycle (PDLC) The process containing the five
phases of program development:
 analyzing,
 designing,
 coding,
 debugging and
 testing, and
 implementing and
 maintaining application software.
14.explain logical and and relational operators in C
The relational operators are used to compare two of the available values to
understand what relationship the pairs of values share. For example, equal
to, greater than, less than, etc. Here is a list of all the relational operators
used in the C language:
 Equal to
 Not equal to
 Less than
 Greater than
 Less than or equal to
 Greater than or equal to
The logical operators evaluate the logical expression and return a result.
The result is always a Boolean value. A Boolean value determines whether the
expression is true or false.
There are three logical operators in C programming: logical AND(&&), logical
OR(||), and logical NOT (!).
15.explain the different branching statements in C

The C programming language is a procedural programming language and


executes the program in a sequential manner from top to down. But
sometimes we need to skip some lines of code according to some of our
requirements. For this, we have Branching Statements in C. Here we are
going to discuss different types of branching statements in C along with
examples of each statement.
Branching Statements in C are those statements in C language that helps a
programmer to control the flow of execution of the program according to the
requirements. These Branching Statements are considered an essential
aspect of the Programming Languages and are essentially used for executing
the specific segments of code on basis of some conditions.
Types of Branching Statements in C
Conditional Branching Statements in C
 if Statement
 else Statement
 else-if Statement
 switch Statement
Unconditional Branching Statements in C
 goto Statement
 break Statement
 continue Statement
16.explain the difference between by the difference between do-while and while
statements with an example
Parameterswhiledo-whileChecking of ConditionIt first needs to check the condition,
and only then can we execute the statement(s).The execution of statement(s) occurs at
least once. After that, the checking of the condition occurs.Semicolonwhile(condition)
No semicolon is present at the end of the while loop.
while(condition);
A semicolon is present at the end of the do-while loop.
Requirement of BracketsWe don’t require any brackets if there is only a single
statement.We would always require brackets in this case.Initialization of VariablesWe
always need to initialize a variable in a condition before the execution of this loop.The
initialization of the variable may occur within or before the execution of the
loop.ControllingThe while loop is an entry-controlled type of loop.The do-while loop
is an exit-controlled type of loop.
17.Programme explain bubble sort technique
#include <stdio.h>
int main()
{
int array[100], n, c, d, swap;

printf("Enter number of elements\n");


scanf("%d", &n);

printf("Enter %d integers\n", n);

for (c = 0; c < n; c++)


scanf("%d", &array[c]);

for (c = 0 ; c < n - 1; c++)


{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1]) /* For decreasing order use '<' instead of '>' */
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}

printf("Sorted list in ascending order:\n");

for (c = 0; c < n; c++)


printf("%d\n", array[c]);

return 0;
}
18.explain different storage classes in detail
C Storage Classes are used to describe the features of a variable/function.
These features basically include the scope, visibility, and lifetime which help
us to trace the existence of a particular variable during the runtime of a
program.
C language uses 4 storage classes, namely:

storage classes in c
1. auto
This is the default storage class for all the variables declared inside a
function or a block. Hence, the keyword auto is rarely used while writing
programs in C language. Auto variables can be only accessed within the
block/function they have been declared and not outside them (which defines
their scope). Of course, these can be accessed within nested blocks within
the parent block/function in which the auto variable was declared.
However, they can be accessed outside their scope as well using the concept
of pointers given here by pointing to the very exact memory location where
the variables reside. They are assigned a garbage value by default whenever
they are declared.
2. extern
Extern storage class simply tells us that the variable is defined elsewhere
and not within the same block where it is used. Basically, the value is
assigned to it in a different block and this can be overwritten/changed in a
different block as well. So an extern variable is nothing but a global variable
initialized with a legal value where it is declared in order to be used
elsewhere. It can be accessed within any function/block.
Also, a normal global variable can be made extern as well by placing the
‘extern’ keyword before its declaration/definition in any function/block. This
basically signifies that we are not initializing a new variable but instead, we
are using/accessing the global variable only. The main purpose of using
extern variables is that they can be accessed between two different files
which are part of a large program.
3. static
This storage class is used to declare static variables which are popularly
used while writing programs in C language. Static variables have the
property of preserving their value even after they are out of their scope!
Hence, static variables preserve the value of their last use in their scope. So
we can say that they are initialized only once and exist till the termination of
the program. Thus, no new memory is allocated because they are not re-
declared.
Their scope is local to the function to which they were defined. Global static
variables can be accessed anywhere in the program. By default, they are
assigned the value 0 by the compiler.
4. register
This storage class declares register variables that have the same
functionality as that of the auto variables. The only difference is that the
compiler tries to store these variables in the register of the microprocessor if
a free register is available. This makes the use of register variables to be
much faster than that of the variables stored in the memory during the
runtime of the program.
If a free registration is not available, these are then stored in the memory
only. Usually, a few variables which are to be accessed very frequently in a
program are declared with the register keyword which improves the running
time of the program. An important and interesting point to be noted here is
that we cannot obtain the address of a register variable using pointers.

19.explain structure with an example


The structure in C is a user-defined data type that can be used to group
items of possibly different types into a single type. The struct keyword is
used to define the structure in the C programming language. The items in
the structure are called its member and they can be of any valid data type.
C Structure Declaration
We have to declare structure in C before using it in our program. In
structure declaration, we specify its member variables along with their
datatype. We can use the struct keyword to declare the structure in C using
the following syntax:
Syntax
struct structure_name {
data_type member_name1;
data_type member_name1;
....
....
};
The above syntax is also called a structure template or structure prototype
and no memory is allocated to the structure in the declaration.
C Structure Definition
To use structure in our program, we have to define its instance. We can do
that by creating variables of the structure type. We can define structure
variables using two methods:
1. Structure Variable Declaration with Structure Template
struct structure_name {
data_type member_name1;
data_type member_name1;
....
....
}variable1, varaible2, ...;
2. Structure Variable Declaration after Structure Template
// structure declared beforehand
struct structure_name variable1, variable2, .......;
Access Structure Members
We can access structure members by using the ( . ) dot operator.
Syntax
structure_name.member1;
strcuture_name.member2;
In the case where we have a pointer to the structure, we can also use the
arrow operator to access the members.
20.What are pointers explain called by value explain call by value and call by
reference
A pointer is nothing but a memory location where data is stored. A pointer is
used to access the memory location. There are various types of pointers such
as a null pointer, wild pointer, void pointer and other types of pointers.
Pointers can be used with array and string to access elements more
efficiently.
here are two methods to pass the data into the function in C language, i.e.,
call by value and call by reference.

call by value and call by reference in c


Let's understand call by value and call by reference in c language one by
one.

Call by value in C
In call by value method, the value of the actual parameters is copied into the
formal parameters. In other words, we can say that the value of the variable
is used in the function call in the call by value method.
In call by value method, we can not modify the value of the actual parameter
by the formal parameter.
In call by value, different memory is allocated for actual and formal
parameters since the value of the actual parameter is copied into the formal
parameter.
The actual parameter is the argument which is used in the function call
whereas formal parameter is the argument which is used in the function
definition.
Let's try to understand the concept of call by value in c language by the
example given below:

#include<stdio.h>
void change(int num) {
printf("Before adding value inside function num=%d \n",num);
num=num+100;
printf("After adding value inside function num=%d \n", num);
}
int main() {
int x=100;
printf("Before function call x=%d \n", x);
change(x);
printf("After function call x=%d \n", x);
return 0;
}

Call by Value Example: Swapping the values of the two variables


#include <stdio.h>
void swap(int , int);
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(a,b);
printf("After swapping values in main a = %d, b = %d\n",a,b); }
void swap (int a, int b)
{
int temp;
temp = a;
a=b;
b=temp;
printf("After swapping values in function a = %d, b = %d\n",a,b); //
Formal parameters, a = 20, b = 10
}
Call by reference in C
In call by reference, the address of the variable is passed into the function
call as the actual parameter.
The value of the actual parameters can be modified by changing the formal
parameters since the address of the actual parameters is passed.
In call by reference, the memory allocation is similar for both formal
parameters and actual parameters. All the operations in the function are
performed on the value stored at the address of the actual parameters, and
the modified value gets stored at the same address.
Consider the following example for the call by reference.
#include<stdio.h>
void change(int *num) {
printf("Before adding value inside function num=%d \n",*num);
(*num) += 100;
printf("After adding value inside function num=%d \n", *num);
}
int main()
{
int x=100;
printf("Before function call x=%d \n", x);
change(&x);//passing reference in function
printf("After function call x=%d \n", x);
return 0;
}
Call by reference Example: Swapping the values of the two variables
#include <stdio.h>
void swap(int *, int *);
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(&a,&b);
printf("After swapping values in main a = %d, b = %d\n",a,b);
}
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a=*b;
*b=temp;
printf("After swapping values in function a = %d, b = %d\n",*a,*b); //
Formal parameters, a = 20, b = 10
}

You might also like