0% found this document useful (0 votes)
26 views

Question Bank Programming in C

This document contains a list of questions related to programming in C language. It includes short 2 marks questions covering various topics like data types, operators, control structures, functions, arrays etc. The questions aim to test the fundamental concepts and syntax aspects of C programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Question Bank Programming in C

This document contains a list of questions related to programming in C language. It includes short 2 marks questions covering various topics like data types, operators, control structures, functions, arrays etc. The questions aim to test the fundamental concepts and syntax aspects of C programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Page No.

QUESTIONS BANK
SUBJECT: PROGRAMMIN IN C

2 MARKS SHORT QUESTIONS

I) What are the rules for naming an identifier? [COi/POI]


2) Write an example on usage of conditional operator. [COI/PO2]
3) What is type casting. Write with a suitable example. [COI/PO2]
4) What is the difference between && and&. [COi/POi]
5) Write down the syntax and example on statements: printf, scanf [COI/PO2]
6) What is the use of getchar() and putchar(). [COi/POi]
7) State the role of break statement in switch .. case control structure. [COi/POi]
8) How does bitwise operator XOR works? [COI/PO2]
9) Identify valid and invalid statements below: [COI/PO2]
int a+b;
char long;
int x,y,z,p,q,w,e,r,t,y,u,i;
float QWE_TY;

10) Find the output when we execute the below statements: (COI/PO2]
int x,y,z,a;
x=30;y=20;z= IO ;
a=x>y>z;
printf("o/od",a);
11) Find the output when we execute the below statements: [CO I/PO2]
int y,z,a;
y=3; z=4;
a=y* =zJ=2;
printf("o/od",a);
12) Find the output when we execute th e below srntcmcnts: [CO I/PO2]
int a,b;
a=20;
b=a» l;
printf("¾d ¾d",a,b);
13) Find the output when we execute the below statements: [COI /PO3]
int a,b,c,e;
a= IO; b=20; c=30;
e=(a>b)II (b<c) && (c==50);
printf ("o/od",e);
14) Find the output when we execute the below statements: [COI /PO3]
int a,b,c,d,e;
a=IOO;b=50;c=30;d=O;
e=(a>=b>=c>=d);
printf("o/od",e);
15) what will be the output and why? [COI /PO3]
#include<stdio.h>
void main()
{ int x,y; x=JO; y=IO;
if(x/xo/ox) printf("lt is summer");
else printf("it is rainy");
}
16) what will be the output and why? [COI/PO3]
#include<stdio.h>
void main()
{ int s;
Page No. 2

s=(0= =0) ? 0 : I ;
if(!s) printft"my land is beautiful");
else printf("my country is great");

17) what will be the output and why? [CO1/PO3]


main()
{ int k=-2, j=4;
switch(k/=j/k)
{ default: printft"default");
case 0: printf("zero");
case I: printf("one");
case 2: printf("two");

}
18) what will be the output and why? [COI/PO 2]
#include<stdio.h>
void main()
{ float a=9.876;
switch(a)
{ case 9: printf("CATHY"); break;
case 9.8: printf("MADDY"); break;
case 9.876: printf("NANCY"); break;
default: printf("SUNNY");
}
}
19) what will be the output and why? [CO1/PO2]
#include <stdio.h>
#define A 1 + 2
#define B 3 + 4
int main()
{
int var = A * B;
printf("¾d\n", var);

20) #include <stdio.h> [CO1/PO2]


int main()
{
if (printf("geeks") != 5)
{ }
else
printf(" geeksforgeeks ");
return 0;

21) State the difference between break and continue while using in a loop control
statements.
[CO2/PO2]
22) State the syntax of do .. while loop? [CO2/PO I]
23) What is an array ? What are the types of it? How to initialize values to a
1D array during its
declaration.
[CO2/PO2]
24) Write down the syntax and example of for statement.
[CO2/PO2]
25) ,W hat is an infinite loop? ,[CO2/PO2]
26) How to interact with all the elements of a matrix using simple loop control
statements?
[CO2/PO2]
27) State the difference between while and do .. while
[CO2/PO2]
28) Differentiate between a for loop and a while loop? What are it uses? [CO2/PO
2]
29) Why is it necessary to give the size ofan array in an array declaration?
[CO2/PO I]
30) Define Conditional control structure and its types [CO2/PO I]
31) What is the use of break statement [CO2/PO 1]

J
Page No. 3

[CO2/PO2]
32) What is continue statement and why we use it ? [CO2/PO2]
33) Give out the syntax of for loop with an example . (CO2/PO3]
34) what will be the output and why?
main()
{ int iJ :

i=0;j =400;
while(i<j) --j; ++i;
printf("%d", i - j );
} [CO2/PO3]
35) what will be the output and why?
main()
{ int K;
for(K=0; K<printf("HELLO") ; K++)
printf("%d" ,K);
}
[CO2/PO2]
36) what will be the output and why?
main()
{ printf("%c", "abcdef'[4]); }

[CO3/PO2]
37) State the difference between recursive and iterative process.
write a function which can return
38) What is the role ofreturn statement in a function? Can we
[CO3/PO 2]
more than one value using return statement?
prototype declarat ion. State the differen ce between
39) Write the syntax and example on function
formal parameters and actual paramete rs. [CO3/PO 2]
2]
40) Explain about the characteristics of storage classes: static, register. [CO3/PO
function s? [CO3/PO 1]
41) What is nesting of
2]
42) What is the difference between strcmp() and strncmp() functions? [CO3/PO
43) Explain what is call by reference? [CO3/PO3]
44) What is storage class. What are the different storage classes in C? [CO3/PO2]
45) What is the difference between Strings and Arrays? [CO3/PO2]
an UDF? [CO3/PO1]
46) What is a function? How to define
s? [CO3/PO1]
47) What are built in function
formal argumen t and actual argume nt? [CO3/PO 2]
48) Difference between
is register variable? Why we use it? [CO3/PO 1]
49) What
[CO3/PO 2]
50) Distinguish local variable and global variable
s? [CO3/PO 2]
51) Define static variable? how it differs automatic variable
[CO3/PO1]
52) Define Function prototype? give out its syntax?
types? [CO3/PO 1]
53) what is storage classes? list out the different
54) Find output:
main() [CO3/PO1]
{ int a=15 b=l9·
' '
int x=sum(a,b);
printf("%d",x); }
int sum(int x, int y)
{ int c=x+y;
return(x);
return(y);
}
55) Find output: [CO3/PO1]
main()
{ static int a= I;
printf("%d",a++ );
if(a<=4)
main();

56) What is a pointer ? How t d I • .


example . . o ec are a pointer? Explain how a pointer works, with a suitable
[CO4/PO2]
Page No. 4

calling. [CO4/PO3]
57) Differentiate between call by value and call by address in function
on and dynami c memory allocation.
58) State the difference between static memory allocati (CO4/PO2]
[CO4/POI]
59) State the syntactical difference between malloc( ) and calloc( ). [CO4/P O3]
60) What is the advantage of a character pointer over character array? [CO4/POI]
61) What the difference between structure and array. [CO4/POI]
62) What is bit field in structure? [CO4/PO2]
63) What is the typedef declaration? Give suitable example. [CO4/POI]
64) Write an example on nested structure. [CO4/POI]
65) When to user-> (a1TOw) operator.
[CO4/PO3]
66) Find Output:
main()
{ int x[5)={ 15,20,7,5,99};
printf("¾d %d %d", *(&x[3]), x[3], 3[x]);

[CO4/PO3]
67) Find Output:
main()
{ char *ptr;
ptr="GUNUPUR";
printf("¾c", *(&(*ptr)));

[CO4/PO3]
68) Find Output:
#include<stdio .h>
int x=-10, y=20;
void main()
{ iner(x,&y);
printf("x=¾d, y=¾d",x,y);
}
void iner(int a, int *p)
{ int x=O;
a=a+l;
*p=*p+l;
printf("a=¾d, x=¾d",a,x);

[CO4/PO3]
69) Find Output:
int qq(int a, int b)
{ return a*b;
void main()
{ int i=5j=6,c;
c=qq(qq(i++, ++j),qq(++ij++));
printf("¾d",c);

[CO4/PO3]
70) Find Output:
typedef struct s I {
float a,b;
struct gl {
double c,d;
};
} new!;
int main()
{
cout << sizeof{newl) << end!;
return O;
.r LONG QUESTIONS:

I)
a. Write down the syntax of else if ladder and
Page No,

switch .. case and then state the difference


s

est among 3 numbers using switch .. case


between them. Write a program to find great [CO1/PO2J
the flowc hart and write algorithm for
b. What is an algorithm and flowchart? Draw [COI/PO3J
prime or not.
accepting a number and check whether it is
2)
input a number and check whether it is
a. Write an algorithm and draw flowchart to [COI/PO3J
Annstrong or not. [COi/POi]
b. Explain the use of each of the following:
i. /*an d*/
ii. Header files
111. Basic Data types
3) [CO1/PO2J
with an example.
a. Explain the following & illustrate each of them
i. Increment & Decrement operator.
ii. Conditional operator.
iii. Bitwise operator. [CO1/PO2]
b. Elaborate the usage of :
i. fonnat specifiers
ii. escape sequence characters
iii. symbolic constants in programming?
4)
ents available 'C'. Explain each of them
a. What are the different types of control statem [COI/PO2J
with example? c
a simple calculator for performing: arithmeti
b. Explain switch - case statement. Design [COI /PO3]
and relational operations.

5) a c program. [CO1/PO2]
a. Explain briefly about the basic structure of
the difference between switch .. case and
b. Write down the syntax of else ifladder. State
ual numbers and find the greatest using
else if ladder. Write a program to input 3 uneq [COI/PO2J
switch.. case.
6) a program to input 3 co-efficient values
a. Write down the syntax of else .. if ladder. Write
using else ifladder. [COI/PO2]
and find the real roots of a quadratic equation
tor and Write a program to find the greatest
b. Write down the syntax of conditional opera [COI/PO2]
among 5 integers using conditional opera tors.
7)
and two operands. Find the result as per
a. Write a program to accept arithmetic operator [COI/PO2]
r.
the operator symbol entered using else if ladde est using else if ladder.
and find the great
b. Write a program to input 4 unequal numbers [COI/PO2]

8)
and test it for vowel or not using
a. Write a program input a lowercase character [COI/PO2]
swi!ch .. case. . I-
the digit given withi n( I to 7), i.e:
b. Wnte a program to display weekday as per [COI /PO2]
h .. case
Sunday, 2- Monday, 3-Tuesday etc. Use switc

9)
ces A(3x4), B(4x3). Perform matrix
a. Writ~~ pr?gram to_input values into two matri [CO2/PO3]
mu!t•plJcation and display the resultant matri x.
an array having elements in sorted order.
b. rn~e . a prog~a'!1 t~ apply binary_ search on h. [CO2/PO3]
xp am how 1t 1s different from Imear searc
10)
it using insertion sort in
c. Writed~ program to accept IO numbers in to an array and sort
ascen mg order [CO2/PO3]
.
Page No. 6

program to h'
Ex pla in how the Bu bble sort works? Write a app
IY t is method to sort a
d. [C02/P03]
string in descending order.
of series : 1, 3,s, ... 21
1I)
gra m to dis pla y the fac torial of all the numbers
e. Write a pro [C02/P03]
I k h · num bers and perfect numbers exi st within
. ow many pri me
f. Write a program to c 1ec [C02/P03]
lto 100.
Write a
12) Ex plain how to initialize values into an array?
types. [C02/P03]
g. What is an array and its nts of ID array and 20 array.
int era ct wi th ele me
program to
the difference
of wh ile, do .. wh ile and for statement. State
tax [C02/P03]
h. Write down the syn ng suitable example.
wh ile and do .. wh ile usi
between
table program to
13) can be dec lared and initialized? Write a sui
I. Explain how an array [C02/P02]
ele me nts .
interact with 1-D array ents using a suitable
exp lain the syn tax of wh ile, do .. while and for statem [C02/P02J
J. Briefly
example.

ntrol loop with


14) betwe en En try Controlled vs. Exit Co
k. Write down the dif fer enc e 'Z' using while.
Wr ite a pro gram to pri nt Alphabets from 'A ' to [C02/P02]
suitable example.
number using
to inp ut a positiv e intege r and its equivalent binary [C02/P02]
1. Write a program
loop.
15) 4 x 4 matrix and find the
principal diagonal.
to inp ut eleme nts into [C02/P02]
m. Write a program
not. [C02/P03]
to acc ept a num ber test whether it is palindrome or
n. Write a program
positive integers.
16) the greate st com mon divisor of given two
o. Write a progra m to fin d [C02/P02]
it is Ar ms tro ng number
program to inp ut a pos itive number and test whether [C 02 /P03]
p. Write a
or not.

not. [C02/P03]
17)
m to inp ut a num ber and check whether it is prime or its diagonal
Write a progra find the sum of
q.
ues into a 4X4 matrix and
r. Write a program to input val [C02/P02]
elements .
18) 1,4,9,16,25 .... .. n where
2 n is given as
nt a series of num ber s
s. Write a program pri [C02/P03]
. it in ascend ing order
inp~t.
m to accept IO num bers m to an array and sort
t. Wnte a progra [C02/P03]
alphabets in
_19) / u.
m to accept a string in to a character array and sort it's [C02/P03]
\./ Write~ progra
asc~ndmg order. [C02/P03]
te a pro~am generate pyramid given below:
v. Wn
I 2 3
I 2 3 4 5
2 3 4 5 6 7

v w.
20)
Write a progra
A
A 8 C
ow·
m generate pyramid given bel . [C02/P03]

A 8 CD E
A B C D EF G
t I .
x. Write a program to inpu va ues mto n 4X4 matrix and displa
y the transpose of it.
[C02/P02]
r
2I)
y. Write a program to print the
pyramid
Page No. 7

[C02/P03J
5
56
567
56 78
56 78 9
ng while. [C 02 /P0 3]
factorial of a given +ve number usi
z. Write a program to find the
22) an integer array and counts
how
Wr ite a pro gra m to cre ate an UDF which accepts [C 03 /P0 3]
a.
ny pri me num ber s exi st in the array. [C 03 /P0 2]
ma ), strcpy()
syn tax and exp lain on functions: strcmp(), strrev(
b. Write the

23) What is the difference


ements for writing an UDF?
c. What are the necessary stat lain with a suitable example.
and formal parameters? Exp
between actual parameters [C 03 /P0 2]
mples.
categories with suitable exa
Wh at are the function categories ? Explain all the [C 03 /P0 2]
d.

a
24) a iterative function? Write
n? How it is different from
e. What is a recursive functio urs ive fun ction and also
of a given number using rec
program to find the factorial [C03/P03J
using iterativ e fun ctio n. [C03/P02J
lain all the stor age clas ses and their characteristics.
f. Briefly exp
of vowels present in the
25)
ite a pro gra m to acc ept the string and count the number [C 03 /P0 3]
g. Wr
ng. ng string han dling
stri not without usi
Wr ite a pro gra m to test a string is palindrome or [C0 3/P02J
h.
functions.
(), subtract() and
26) m wh ich con tains three UDF's namely add
i. Wr ite a C pro gra uments and calculate and
epts two integers as their arg
multiply() . Each function acc [C02/P03]
return the results the y are equ al or not using
gra m to acc ept two strings and check whether
j. Write a pro [C03/P02]
UDF.
4 matrices. Create an UDF
which accepts
27) inp ut valu es into two 4X
k. Write a program to . . [C03/P02]
per form ma ~ix additi?n.
the ~wo ma trices and g is palindrome or not.
te a pro gra m to cre ate a rec ursive function to test a strm
1. Wn [C03/P03]
m using a recursive
28)
to input two num bers and find the GCD of the
m. Writ~ a program [C03/POJ]
fun~tlo n. bers using ·
te Fibonacci series ofN num a recursive
n. Wnte an.program to genera [C03/P03]
functio
29) s with 't bl
o. Write down the diff erence between the following sm a e example for each:
(ii)while vs. do .. while
[C03/P03]
ress
(iii)call by value vs call by add
p. How to define an UD F? What is the diffi ce between actual parameters and formal
role of ret statem eren • ut 5 numbers
parameters? Wh at is the urn ent? Write a program to mp
d fi larg est, sma llest usin g UD F [C03/P02]
an md ·
30) .
GCD of two i1 . . [C03/P03]
q. W~ite a program to find storag I 1teg e1s u~mg a recursive function. difference
r. Briefly explain all the racteristics. State the
~xaas~esleand then· cha
between auto and static with a~ [C03/P03]
p .
Page No. 8

a. What is a pointer ·
? How a pomter .
of E can be used to navigate between memory locations
an ~rray 7 xplain briefly with a suitable example. [CO4/PO2]
.
b. tWhat 1s the advantage Of a chat.acter pointer .
over a character array ? Explain the
enns array of pointers, pointe to pointer. [CO4/PO2]

c. ~xplain the syntax and example on malloc(), calloc(). Write a program to allocate N
mteger. memory , store the numbers, find the average of them using dynamic memory
all~cation. [CO4/PO3]
d. Wnt~ short not~s on any 3 out of 5 [CO4/PO1 ]
1. Dynamic memory allocation
ii. String handling
iii. Uses of Pointers
iv. Nested loops

e. Write a program to input two numbers and using call by address concept find LCM
and GCD. [CO4/PO3]
f. Write a program to input a string and then using pointer find how many vowels
present in the string. [CO4/PO3]
34)
g. Write a program to create an UDF which accepts a number and finds the reverse of it
using call by address concept. [CO4/P03]
and then concatenates
h. Write a program to create an UDF which accepts two strings
both strings (use character pointers as parameters in UDF) [CO4/P03 ]
35)
i. Write a program to create user defined function called swap having two integer
pointers as its arguments and it has no return value. Call this function for
interchanging two values using call-by-address. [C04/P03 ]
into an array. Create an UDF which accepts the
j . Write a program to input 10 integers
base address of array and finds the sum of even numbers and sum of odd numbers
separately. [CO4/PO3]
36)
k. Write a program to create a user defined function which accepts a string using a
character pointer and returns the length of the string. [CO4/PO3]
I. Write a program to store N float values using DMA and create an UDF which finds
the sum of them. [CO4/PO3]
37) : Book code, book
m. Write a program to create a structure BOOKS having members
name, author, cost. Store 10 books details using structure array. Find the total cost of
all books [CO4/P03]
complex to represent a complex number.
n. Write a program to create a structure called
Perform addition of two complex numbers using UDF [CO4/PO3 ]
38) Store five
o. Write a program to create a structure for employee code, name and salary.
employee details using structure array and display only employee names whose salary
is greater than 25000. [CO4/PO3 ]
p. Write a program to create structure called ITEM having members: item code, name,
price. Create a structure array of size IO. Store the item details and then using a
structure pointer display all the items whose price>=500 [CO4/PO3]

39)
q. What is a pointer ? How a pointer can be used to navigate between memory locations
of ID ~rray and 2D array? Explain briefly with a suitable example. [CO4/PO3]
r. What 1s the adva~tage of a character pointer over a character array? Explain the
terms: array of pomters, pointe to pointer. [C04/PO3]
40)
s. Explain th~ syntax and example on malloc(), calloc(), realloc(). Write a program to
allocate N mteger memory and then input the numbers and find the average.
[CO4/PO3]
Page No. 9

having two integer


t. Write a program to create user defined function called swap
function using call-by-
pointers as its arguments and it has no return value. Call this
[CO4/PO3]
address.
41) UDF which accepts the
u. Write a program to input 10 integers into an array. Create an
sum of odd numbers
base address of array and finds the sum of even numbers and
[CO4/PO3]
separately.
ry allocation. Then find
v. Write a program to store N values using dynamic memo
MIN(). [CO4/PO3]
largest and smallest number present in it using UDFs MAX() and
42) array of structure. The
w. Write a program to store 11 cricket players' details into an
average. Create an
structure having member's player name, team name and batting
>=30. [CO4/P03]
UDF which displays the name of players whose batting average is
g members: rollno,
x. Write a program to create a structure called SUBJECTS havin
store 10 students
physics, chemistry, maths, total marks. Create a structure array to
[C04/P03]
marks. Calculate the total marks of each student.

You might also like