Computer Concepts Programming
Computer Concepts Programming
Computer Concepts Programming
C] getche()
D] Both (B) and (C)
10) What is the output of this program ?
void main() {
int a=b=c=10;
a=b=c=50;
printf(\n %d %d %d,a,b,c); }
A] 50 50 50
B] Compile Time Error
C] 10 10 10
D] Three Gaebage Value
11) Which format specifier is used to print the values of double type variable
A]%If
B]%Id
C]%Iu
D] %f
12) What will be the output of the following program?
Void main ( ) {
Double x=28;
Int r;
R= x%5;
Printf (\n r=%d, r); }
A] r= 3
B] Run time Error
C]Compile time Error
D]None of the Above
13) What the follwing function call mean?
Strcpy(s1 , s2 );
A]copies s1 string into s2
B]copies s2 string into s1
C]copies both s1 and s2
D] None of these
14) What will be the output of the following program?
Void main( ) {
Int x []= {10,20,30,40,50};
Print f ( \n %d %d %d %d , x [4] ,3[x] ,x[2] ,1[x] ,x[0] ); }
A] Error
B] 10 20 30 40 50
C] 50 40 30 20 10
D]None of these
15) Which of the following is not s keyword of C ?
A] auto
B] register
C] int
D] function
16) What will be the out put ?
Void main ( ) {
Char a[] = INFO ;
a + +;
void main ( ) {
int x;
unsigned y;
printf(\n%d %d, sizeof(x), sizeof(y) ); }
A] 22 B] 24 C] 44 D] None of these
35) int **x;
A]x is a pointer to pointer B] x is not pointer
C] x is long D] None of these
36) What will be the output ?
void main ( ) {
printf(\n %d %d, 10&20, 10/ 20); }
A] 00 B] 10 10 C] 0 30 D] 20 20
37) Which of the following is used as a string termination character ?
A] 0 B] \0 C] /0 D] None of these
38) What will be the output ?
void main ( ) {
int I= 48;
printf(\n %c %d ,I,I ); }
A] Error B] 48 48 C] 1 48 D] 0 48
39) A static variable by default gets initialized to
A] 0 B] blank space C] 1 D] garbage value
40) Find out on which line no .you will get an error ?
Line 1: void main ( )
Line 2: {
Line 3: print(\n Hello World)
Line 4: }
A] Line 1 B] Line 2 C] Line 3 D] Line 4
41) What will be the output of the following program ?
void main ( ) {
int x=10,y=20;
printf (\n %d,x,y); }
A] 10 B] 20 C] 10 20 D] None of these
42) Which function reallocates memory ?
A] realloc B] alloc C] malloc D] None of these
43) What will be the size of following union declaration?
Union Test {
Int x;
Char y;
Float z; } ;
A] 7 bytes B] 4bytes C] 1byte D] 4 bytes
44) A declaration float a,b; accupies ______of memory ?
A] 1 bytes B] 4bytes C] 8byte D] 16 bytes
45) What is the output of the following program ?
void main() {
int x=40;y=30;z=80;
if(x<y<z)
printf(\n Hello world);
else
printf(\nGood by);
A] Hello world B]Good by C]Compile time error D]None of these
46) Which of the following is not a relational operator?
A]! B] != C]>= D]<
47) what will be the output ?
void main(){
char *p=Hello world;
int *q;
p++;
q = (int *)p;
q++;
printf(\n %s\n%s,p,q); }
A] ello world B]Error
Ello world
C] ello world D]ello world
Lo world llo world
48) which of the following is an operator in C?
A] , B] $ C] @ D] None of these
49) What is the output of the following code?
Void main() {
Int c=0, d=5,e=10,a;
A=c>1?d>1||e>1?100:200:300;
Printf(a=%d,a); }
A] a=300 B]a=100 C] a=200 D] None of these
50) Which among the following is a unconditional control structure?
A] do-while B] if else C] goto D] for
51) Which of the following language is predecessor to C
Programming Language?
A] A B]B C] BCPL D]C++
52) C programming language was developed by
A] Dennis Ritchie B]Ken Thompson C] Bill Gates D] Peter
Norton
53) C was developed in the year ___
A] 1970 B] 1972 C] 1976 D] 1980
54) C is a ___ language
A] High Level B] Low Level C] Middle Level D] Machine Level
55) C language is available for which of the following Operating
Systems?
A] DOS B] Windows C]Unix D] All of these
56) Which of the following symbol is used to denote a pre-processor
statement?
A] !B]# C] ~ D];
57) Which of the following is a Scalar Data type
A] Float B] Union C] Array D] Pointer
58) Which of the following are tokens in C?
A] Keywords B]Variables C]Constants D]All of the above
59) What is the valid range of numbers for int type of data?
A] 0 to 256 B] -32768 to +32767 C] -65536 to +65536 D] No
specific range
60) Which symbol is used as a statement terminator in C?
A] ! B] # C]~ D] ;
61) Which escape character can be used to begin a new line in
C?
A] \a B] \b C] \m D] \n
62) Which escape character can be used to beep from speaker in
C?
A] \a B] \b C] \m D] \n
63) Character constants should be enclosed between ___
A] Single quotes B] Double quotes C] Both a and b D]None of These
64) String constants should be enclosed between ___
A] Single quotes B] Double quotes C] Both a and b D]None of These
65) Which of the following is invalid?
A] B] C] a D] abc
66) The maximum length of a variable in C is ___
A] 8 B] 16 C] 32 D] 64
67) What will be the maximum size of a float variable?
A] 1 byte B] 2 bytes C] 4 bytes D] 8 bytes
68) What will be the maximum size of a double variable?
A] 1 byte B] 4 bytes C] 8 bytes D] 16 bytes
69) A declaration float a,b; occupies ___ of memory
A] 1 byte B] 4 bytes C] 8 bytes D] 16 bytes
70) The size of a String variable is
A] 1 byte B] 8 bytes C] 16 bytes D] None
71) Which of the following is an example of compounded
assignment statement?
A] a = 5 B ]a += 5 C] a = b = c D] a = b
72) The operator && is an example for ___ operator.
A] Assignment B] Increment C] Logical D] Rational
73) The operator & is used for
A] Bitwise AND B] Bitwise OR C] Logical AND D] Logical OR
A] 2 B] 3 C] 4 D] 6
105) A statement differs from expression by terminating with a
A] ; B] : C] NULL D] .
106) What should be the expression return value for a do-while to
terminate
A] 1 B] 0 C] -1 D] NULL
107) Which among the following is a unconditional control structure
A] do-while B] if-else C] goto D] for
108) continue statement is used
A] to go to the next iteration in a loop
B] come out of a loop
C] exit and return to the main function
D] restarts iterations from beginning of loop
109) Which operator in C is called a ternary operator
A] if..then B] ++ C] ? D] ()
110) Which of the following header file is required for strcpy()
function?
A ]string.h B] strings.h C] files.h D] strcpy()
111) The meaning of conversion character for data input is
A] Data item is a long integer
B] Data item is an unsigned decimal integer
C] Data item is a short integer
D] None of the above
112) The conversion characters for data input means that the data
item is
A] An unsigned decimal integer
B] A short integer
C] A hexadecimal integer
D] A string followed by white space
113) An expression contains relational, assign. ment and arithmetic
operators. If Parenthesis are not present, the order will be
A] Assignment, arithmetic, relational
B] Relational, arithmetic, assignment
C] Assignment, relational, arithmetic
D] Arithmetic, relational, assignment
114) Which of the following is a key word is used for a storage class
A] printf B] external C] auto D]scanf
115) In the C language 'a represents
A] a digit B] an integer C] a character D] a word
116) The number of the relational operators in the C language is
A] Four B] Six C] Three D] One
117) A compound statement is a group of statements included
between a pair of
A] double quote B] curly braces C] parenthesis D] a pair of /s
118) A Link is
A] a compiler B] an active debugger C] a C interpreter D] a analyzing tool in C
119) The continue command cannot be used with
A ] for B] switch C] do D] while
120) In C, a Union is
A ] memory location B] memory store C] memory screen D] None
of these
121) When the main function is called, it is called with the
arguments
A ]argc B] argv C] None of these D] both a & b
122) A multidimensional array can be expressed in terms of
A] array of pointers rather than as pointers to a group of
contiguous array
B] array without the group of contiguous array
C] data type arrays
D] None of these
123) C allows arrays of greater than two dimensions, who will
determined this
A] programmer
B] compiler
C] parameter
D]None of these
124) A pointer to a pointer in a form of
A] multiple indirection B] a chain of pointers C] both a and b D]
None of these
125) Pointers are of
A] integer data type B] character data type C] unsigned integer
data types
D] None of these
Short Questions
1. What is variable?
2. What is constant?
3. How many bytes are required to store integer type value?
4. How many bytes are required to store float type value?
5. How many bytes are required to store char type value?
6. How many bytes are required to store double type value?
7. What is main difference between variable and constant?
8. What is logical variable?
9. What is global variable?
10. How long is word?
11. How long is a byte?
12. How does a programmer finds coding errors?
13. Describe the appearance of machine code?
14. Whether the program in c can be executed by computer directly ?
15. What is language processor?
16. What is purpose of language processor?
17. What are major disadvantages of machine code?
18. Give the general syntax of conditional operator?
19. Which are relational operator?
20. Which are logical Operators?
21. Which are Bitwise Operators?
22. Which are unformatted input output functions?
23. Which are formatted input output functions?
24. What is the use of getchar() function?
25. What is the use of getch() function?
26. What is the use of getche() function?
27. What is Disk IO Function?
28. What do you mean by consol IO functions?
29. Give syntax of simple if stmt
30. Give syntax of simple if else stmt
31. Give syntax of simple nested if else stmt?
32. Define Program
33. What is nested loop?
34. What is process loop?
35. What is Syntax Error?
36. What is Logical Error?
37. What is Run Time Error?
38. Define Array
39. Give general Syntax to declare One dimensional array
40. Give general Syntax to declare two dimensional array
41. What is function?
42. What is built in function?
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74. What is mean by the comparision and logical operator?How are they different from the arithmetic
and assignment operator?
75. List out the different operators involve for comparision and logical decision making in C.
76. What is mean by the equality operator?How do these differ from an assignment operator.
77. Explain the following bitwise operators
i)Bitwise AND ii) Bitwise OR iii) BitwiseXOR iv) Bitwise Left Shift v) Bitwise Right Shift
78. What is unary operator? List out the different operator involve in the unary operator.
79. Distinguish between binary minus and unary minus.
80. What is modulus operator and how does it operate in C.
81. What is an expression? How is an expression different from the variables?
82. What are the different type of statement used in C.
83. What are the salient features of standard input and output file
84. Explain the following stements:
i)getchar() ii)putchar() iii)EOF
85. What is the scanf() and how does it differ from the getchar().
86. What are the format codes used along with the scanf().Display the various data types in C.
87. What is the printf() and compare with putchar().
88. What is mean by conditional expression?
89. What is looping in C? What are the advantages of looping?
90. What is the nested for loop?
91. Compare while loop and for loop with example.
92. What is crucial importance of main() in C.
93. What is use of continue in C.
94. List out applications of C language.
95. List out the advantages of function. What is mean by call by reference & call by value.?
96. What is the difference betweent call by reference & call by value.
97. What is the purpose of return statement
98. What is mean by register variable and what the scope of it?
99. What role does the fseek() plays and how many arguments does it Have?
100.
What is an array and how array variable differs from ordinary variable. What is an array
indexing explain with an example
101.
When sorting the elements of an array is it necessary to use another array to store the
sorted elements explain?
102.
What is the function and list out advantages and disadvantages of functions?What is
mean by function argument, function call and return value?
103.
How is the #include directive is used?
104.
How can #define directive be continued to anew line
105.
Summarize the purpose of string.h function.
106.
What is mean by member or field of structure
107.
What is the difference between structure declaration and structure initialization?
108.
Explain the various modes used in file operation?
109.
What is the purpose of comma operator within which statement does the comma
operator usually appear.
110.
Explain Getw() &Putw function
Long Questions
Q1.What is a computer? Draw a neat label block diagram of a computer and explain the functions of each
unit.
Ans. Computer is an electronic device that takes some data as input process that data and produce some
output.
CentralProcessingUnit
OutputUnit
FiveBasicOperationsofComputer
Q4.What is an operating system. Explain the functions and objectives of an operating system.
OperatingSystem
Itactsasaninterfacebetweentheuserand
thehardware.
Ausercannotrunanapplicationprogramon
computerwithoutOS.
OSisessentials/wthatisforcomputerto
becomeoperational.
IntheabsenceofOSneitheri/pdeviceswill
beabletoprovidedatatocomputernor
memorywillbeabletostoreanythingnorwill
o/pdevicesbeabletoshowtheresult.
MainFunctionsOfOS
Processmanagementfunctions:takescareofcreation&deletion
ofprocesses,schedulingofsystemresourcestodifferent
processesrequestingthem&providingmechanismfor
synchronization&communicationamongprocesses.
Memorymanagementprocesses:Ittakescareofallocation&
deallocationofmemoryspacetoprograminneedofresources.
Filemanagement:Ittakescareoffilerelatedactivitiessuchas
organization,storage,retrieval,naming,sharing&protectionof
files.
Security:Itprotectstheresources&informationofcomputer
systemagainstdestruction&unauthorizedaccess.
CommandInterpretation: Ittakescareofinterpretinguser
commands&directingsystemresourcestoprocessthe
commands.
Q5.What are the basic flowcharting symbols? What functions does each represent?
Ans. Flowchart is a pictorial representation of an algorithm.
Types of software:
are- is a set of
o one or morre programs designed
d
to control the ope
eration and extend
e
System Softwa
he processing
g capability off computer system.
th
Application
A
So
oftware-is a se
et of one or more
m
program
m designed to
o solve a spe
ecific problem
m or to
do
o a specific ta
ask.
SystemSoftware
Q7. Give the size of integer, character, float and long double data types in bytes?
Ans.
Integer = 2bytes
Character=1 byte
Float=4 bytes
Long double=10 bytes
DATATYPES
ANSICsupportsthreeclassesofdatatypes:
1Primarydatatypes(orfundamental).
2Deriveddatatypes.
3Userdefineddatatypes.
PRIMARYTYPEDECLERATION:
Avariablecanbeusedtostoreavalueofany
datatypes.
Thatisthenamehasnothingtodowithitstype.
Thesyntaxfordeclearing avariableisasfollow:
data_type V1,V2,.Vn;
V1,V2.Vn arethenamesofvariablesare
seprated bycomma,s.
Adecleration statementmustbeendwith
semicolon.
EX:int count;
Int number,total;
DERIVEDDATATYPES
Thederiveddatatypessuchas
array,function,structure andpointersare
discussed.
Allccompilerssupportfivefndamental data
types:
1integer(int)
2character(char)
3floatingpoint(float)
4doubleprecesionfloatingpoint(double)
5void
Manyofthemextendeddatatypessuchas
longint andlongdouble
INTEGERTYPES
Integerarewholenumberswih arangeofvalue
supportedbyaparticularmachine.
Thesizeofanintegerthatcanbestoreddepend
onthecomputer.
Ituse16bit(2byte)wordlength.
Limitedrangeofintegeris32768to32767.
Chasthreeclassesofintegerstoragenamely
shortint,int,and longint.
ANSICdefinesthesetypessothattheycanbe
organizedfromsmallesttothelargest.
FLOATINGPOINTTYPE
Floatingpointnumbersarestoredin32bit(4
byte).
FloatingpointnumberaredefinedinCbythe
keywordfloat.
Whentheaccracy providedbafloatnumberis
notsufficent thantypedoublecan beusedthe
definenumber.
Adoubledatatypenumberuses64bit(8byte).
Toextendtheprecesion weuselongdouble.
Longdoubleusethe80bit(10byte).
CHARACTERTYPE
Asinglecharactercanbedefinedasa
character(char)typedata.
Characterareusuallystored8bit(1byte).
Theqalifier signedareunsignedmaybeexplicity
appliedtochar.
Unsignedcharhavevalueb/w0to255.
Signedcharvaluesfrom128to127.
VOIDTYPE
Thevoidtypehasnovalues.
Thisisusuallyusedtospecifythetypeof
function.
Thisfunctionsaidtobevoid.
Itdoesnotreturnanvaluetothecalling
function.
Itcanalsoplaytheroleofgenerictypemeans
thatitcanrepresnet anoftheotherstandard
type.
USERDEFINETYPESDECLERATION
Csupportsafeatureknownastypedefinition.
Itallowsusertodefineanidentifierthatwould
representanexistingdatatype.
Theuserdefineddatatypecanlaterbeusedto
declear variable.
Ittakesthegeneralform
typedef typeidentifier;
Wheretypereferstoanexistingdatatypeand
identifiernewnamegivenothedatatype.
Themian advantageoftypedef isthatwecan
creae meaningfull datatypenamesforincreasing
thereadabilityofprogram.
Another user defined enumarted data type.
Q9. What are operators? Chart various types of operators offered by C language ?
AssignmentOperator
X=8
/*8isassignedtox*/
Y=5
/*5isassignedtoy*/
x=x+5canalsobewrittenasx+=5
y=y*5
canalsobewrittenasy*=5
IncrementandDecrementOperator
Theseareunaryoperatorstheyoperateonsingle
operand.
++ incrementthevalueofthevariablebyone.
decrementthevalueofthevariablebyone.
++x
isequivalentto
x=x+1
x
isequivalentto
x=x1
Theseoperatorsshouldonlybeusedwithvariablesnot
withconstantorexpressions.
Theseoperatorsareoftwotypes:
Prefixincrement/decrement
Postfixincrement/decrement
PrefixIncrement/Decrement
y=++xmeansfirstincrementthevalueofxby
1,thenassignitsvalueintoy.
1.
x=x+1
2.
y=x
y=xmeansfirstdecrementthevalueofxby
1,thenassignitsvalueintoy.
1.
2.
x=x1
y=x
PostfixIncrement/Decrement
y=x++meansfirstassignvalueofxintoy
thenincrementthevalueofxby1.
1.
2.
y=x
x=x+1
y=x meansfirstassignvalueofxintoythen
decrementthevalueofxby1.
1.
2.
x=x1
y=x
RelationalOperators
Operator
<
Meaning
Less than
<=
==
Lessthanorequalto
Equalto
!=
Notequalto
>
>=
Greaterthan
Greaterthanorequalto
LogicalOperators
Operator
&&
||
!
Meaning
AND
OR
NOT
NOT(!)Operator
Condition
False
True
Result
True
False
#include<stdio.h>
#include<conio.h>
voidmain()
{
floatm1,m2,m3,m4,total,per;
printf(entermarksof4subjects);
scanf(%f%f%f%f,&m1,&m2,&m3,&m4);
total=m1+m2+m3+m4;
per=(total/400)*100;
if(per>=85)
printf(grade=A);
elseif(per>=70)
printf(grade=B);
elseif(per>=55)
printf(grade=C);
elseif(per>=40)
printf(grade=D);
else
printf(grade=E);
getch();
}
#include<stdio.h>
#include<conio.h>
voidmain()
{
int year;
clrscr();
printf(enteryear);
scanf(%d,&year);
if(year%100==0)
{
if(year%400==0)
printf(leapyear);
else
printf(notleapyear);
}
else
{
if(year%4==0)
printf(leapyear);
else
printf(notleapyear);
}
getch();
}
#include<stdio.h>
#include<conio.h>
voidmain()
{
int num;
clrscr();
scanf(%d,&num);
if(num%2==0)
printf(numiseven);
else
printf(numberisodd);
getch();
}
#include<stdio.h>
#include<conio.h>
voidmain()
{
intnum,fact=1;
printf(enterthenumber);
scanf(%d,&num);
if(num<0)
printf(nofactorialof()ve
number);
else
{
while(num>1)
{
fact=fact*num;
num=num-1;
}
printf(factorial:%d,fact);
}
getch();
}
#include<stdio.h>
#include<conio.h>
voidmain()
{
int num,sum=0,rem;
Scanf(%d,&num);
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf(sumofdigits=%d,sum);
getch();
}
Foreg:
Num=2345
Sumofdigit=14
#include<stdio.h>
#include<conio.h>
voidmain()
{
int a,b,c;
clrscr();
scanf(%d%d%d,&a,&b,&c);
if(a>b)
{
if(a>c)
printf(larger=a);
else
printf(larger=c);
}
else
{
if(b>c)
printf(larger=b);
else
printf(larger=c);
}
getch();
}
#include<stdio.h>
#include<conio.h>
voidmain()
{
int num;
clrscr();
scanf(%d,&num);
if(num%2==0)
printf(numiseven);
else
printf(numberisodd);
getch();
}
#include<stdio.h>
#include<conio.h>
voidmain()
{
int i=1;
while(i<=10)
{
printf(%d,i);
i=i+1;
}
getch();
}
#include<stdio.h>
#include<conio.h>
voidmain()
{
int i=10;
while(i>0)
{
printf(%d,i);
i=i2;
}
getch();
}
Q19. What is a switch statement. Explain with a program.
Ans. Switch is a built in multiple branch selection statement in C. The switch statement is used when the
selection is based on the vale of single variable or of a simple expression. The value of this expression
may be of type int or char, but not of type double. The syntax of switch statement is:
switch(expression)
{
Case 1:
St1;
St2;
break;
Case 2:
St1;
St2;
break;
default:
}
Program:
switch ( day )
{
case 0: printf (Sunday\n) ;
break ;
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 ;
case 6: printf (Saturday\n) ;
break ;
default: printf (Error -- invalid day.\n) ;
break ;
Q20. Explain the difference between while and do-while loop.
Ans.Syntax of while loop:
while(expression)
{
Statement 1;
Statement 2;
}
Syntax of do while loop:
do
{
Statement1;
Statement 2;
}while(expression);
In while loop ,expression is tested first and then the body is executed. If the expression is evaluated to
true then loop is again executed.
Do-while loop gets executed at least once, where as , it is not necessary in while loop.
Q21. Define Identifiers and Keywords.
Keywords
Ans.All keyword have a fix meaning and these meaning cant be changed.
All keyword must be written in lower case.
Some compiler may use additional keyword that must be identified from C manual.
ANSI C keyword.
break,else,long,switch,int,float,char etc.
Identifiers
Q22. Define the term constant and variable and its types .
Ans. Constant in C reffered to fix Value that dont change during the execution of program. C support
several types of constants as given below:
Numeric Constant
Char Constant
Int Constant
Real Constant
Single Char Constant
String Constant
Variable
A variable is a data name that may be used to store a data value.
A variable may take different times during execution.
Variable names may consist of letters,digit and underscore character .subject to the following
condition:
They must begin with letters some system permits,underscore as the first character.
Upper and Lower case are significant.That is variable total.
eg: int a,b;
float c;
char name;
Q23. Explain the general syntax of a C function with eg.
Ans.Functions is a self-contained subprogram that is meant to do specific, well-defined task.A C
program consist of one or more functions.If a program has only one function then it must be the
main() function.
WAP to find square root of any number.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int num,s;
printf(enter the number);
scanf(%d, &num);
s=sqrt(num);
printf(%d,s);
getch();
}
Q24. What do you understand by recursion.WAP to find factorial of a number using recursion.
Ans.Recursion is a process,when a function calls itself.
For eg :main()
{
printf(this is an example of recursion);
main();
}
#include<stdio.h>
#include<conio.h>
int fact(int n);
void main()
{
int num;
scanf(%d,&num);
F=fact(num);
Printf(fact=%d,f);
getch();
}
Int fact(int n)
{
int factorial;
If (n==1)
return (1);
else
factorial=n*fact(n-1);
return (factorial);
}
The lines starting with # are known as preprocessor directives.When the preprocessor finds a
line starting with the symbol #,it consider it as a command for itself and works accordingly.All the
directives are executed by the preprocessor,and thecompiler does not receive any line starting
with # symbol.
Some feature of preprocessor directives are1. Pre-processor directives begin with the symbol #.
2. There can be only one preprocessor directive on a line
Ans.We have seen macros with arguments can perform task similar to function.
A macro is expanded into inline code so the text of macro is inserted into the code for each macro
call. Hence macro makes the code lengthy and the compilation time increases.On the other hand
the code of a function is written only at one place, regardless of the number of times it is called so
the use of functions makes the code smaller.
In function ,the passing of arguments and returning a value takes some time and hence the
execution of the program becomes slow while in case of macros this time is saved and they
make the program faster.
So functions are slow but take less memory while macros are fast but occupy more memory due
to duplicity of code
Q30. What do you understand by arrays . How to declare and access array elements?
Ans.A collection of objects of the same type stored contiguously in memory under one name.
For ease of access to any member of array
For passing to functions as a groupint A[10]
An array of ten integers
A[0], A[1], , A[9]
double B[20]
An array of twenty long floating point numbers
B[0], B[1], , B[19]
Arrays of structs, unions, pointers, etc., are also allowed
Array indexes always start at zero in C
Declaring Arrays
Static or automatic
Array size determined explicitly or implicitly
Array size may be determined at run-time
Automatic only
Not in textbook
#include<stdio.h>
main()
{
int n, reverse = 0, temp;
printf("Enter a number to check if it is a palindrome or not\n");
scanf("%d",&n);
temp = n;
while( temp != 0 )
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if ( n == reverse )
printf("%d is a palindrome number.\n", n);
else
printf("%d is not a palindrome number.\n", n);
return 0;
}
Q38.Write a program to check whether the given number is Armstrong or not.
Ans. /* Write a program to check armstrong number */
#include<stdio.h>
#include<conio.h>
void main()
{
int num,n,cube,rem,sum;
clrscr();
for(num=100;num<=999;num++)
{
n=num;
sum=0;
while(num>0)
{
rem=n%10;
n=n/10;
cube=rem*rem*rem;
sum=sum+cube;
}
if(num==sum)
printf(armstrong no.);
else
printf(not armstrong no);
}
getch();
}
Q39. Write a program to check the given year is leap year or not.
Ans. /* WAP to find whether year is leap year or not. */
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf(enter year);
scanf(%d, &year);
if(year%100==0)
{
if(year%400==0)
printf(leap year);
else
printf(not leap year);
}
else
{
if(year%4==0)
printf(leap year );
else
printf(not leap year);
}
getch();
}
Q40.WAP to simulate calculator using switch statements.
Ans. #include<stdio.h>
#include<conio.h>
void main()
{
char op;
int c,a,b;
scanf("%c",&op);
scanf("%d%d",&a,&b);
switch(op)
{
case '+':
c=a+b:
printf("%d",c);
break;
case '-':
c=a-b:
printf("%d",c);
break;
case '*':
c=a*b;
printf("%d",c);
break;
}
getch();
}
for(j=0;j<COL1;j++)
scanf("%d",&mat1[i][j]);
printf("enter the values for matrix2:");
for(i=0;i<ROW2;i++)
for(j=0;j<COL2;j++)
scanf("%d",&mat2[i][j]);
printf("multiplication");
for(i=0;i<ROW1;i++)
for(j=0;j<COL2;j++)
{
mat3[i][j]=0;
for(k=0;K<COL1;k++)
mat3[i][j]=mat3[i]][j]+mat1[i][k]*mat2[k][j];
}
printf("resultant matrix");
for(i=0;i<ROW1;i++)
for(j=0;j<COL2;j++)
printf("%d",mat3[i][j]);
getch();
}
Q44.WAP to find out the grade of a student when the marks of four subjects are given. The method of
assigning grade is:
percent>=85
grade=A
percent<85 and percent>=70
grade=B
percent<70 and percent>=55
grade=C
percent<55 and percent>=40
grade=D
percent<40
grade=E
Ans.#include<stdio.h>
#include<conio.h>
void main()
{
float m1,m2,m3,m4,total,per;
printf(enter marks of 4 subjects);
scanf(%f%f%f%f,&m1,&m2,&m3,&m4);
total=m1+m2+m3+m4;
per=(total/400)*100;
if(per>=85)
printf(grade=A);
else if(per>=70)
printf(grade=B);
else if(per>=55)
printf(grade=C);
else if(per>=40)
printf(grade=D);
else
printf(grade=E);
getch();
}
#include<conio.h>
void main()
{
int arr[10]={2,5,4,1,8,9,11,6,3,7},i;
int min,max;
min=max=arr[0];
for(i=1;i<10;i++)
{
if(arr[i]>max)
max=arr[i];
if(arr[i]<min)
min=arr[i]
}
printf("minimum=%d maximum=%d",min,max);
getch();
}
Q46. Write a program to search an element in an array .
#include<stdio.h>
#include<conio.h>
void main()
{
int i,value,arr[5]={23,12,56,98,76};
scanf("%d",&value);
for(i=0;i<5;i++)
{
if(arr[i]==value)
{
printf("value is found");
break;
}
if(i==5)
printf("value not found");
getch();
}
for(j=0;j<COL;j++)
scanf("%d",&mat2[i][j]);
printf("addition");
for(i=0;i<ROW;i++)
for(j=0;j<COL;j++)
mat3[i][j]=mat1[i][j]+mat2[i][j];
printf("matrix3 after addition:");
for(i=0;i<ROW;i++)
for(j=0;j<COL;j++)
printf("%d",mat3[i][j]);
getch();
}
Q48. What is a preprocessor?
Ans.The lines starting with # are known as preprocessor directives.When the preprocessor finds
a line starting with the symbol #,it consider it as a command for itself and works accordingly.All
the directives are executed by the preprocessor,and thecompiler does not receive any line
starting with # symbol.
Some feature of preprocessor directives are1. Pre-processor directives begin with the symbol #.
2. There can be only one preprocessor directive on a line
3. There is no semicolon on a line
4. A directive is active from the point of its appearance till the end of program.
Main functions performed by preprocessor directives are1.Simpe macro substitution
2.Macro with arguments
3.Conditional compilation
Pre-processor Directives
Directives
Functions
#define
#undef
Undefines a macro
#include
#ifdef
#endif
#ifndef
#if
Ans.
In information technology, hardware is the physical aspect of computers, includes not only the
computer proper but also the cables, connectors, power supply units, and peripheral devices such as the
keyboard, mouse, audio speakers, and printers.
The program came to be known as the software,that help computer to run or to do certain task.
Q53.
Ans.
Compilers and interpreters have similar functions: They take a program written in some
programming language and translate it into machine language. A compiler does the translation all at
once. It produces a complete machine language program that can then be executed. An interpreter, on
the other hand, just translates one instruction at a time, and then executes that instruction immediately.
Q54.Write the difference between initialization and assignment of variables in C?
Ans:
1.
2.
3.
4.
Description
Example
&
<<
>>
Looping is the process of repeating of same code until a specific condition doesnt satisfy. In c there are
three types of loop:
(a)loop
(b)while loop
(c)do while
for loop:
This loop is used when we have to execute a part of code in finite times. It is per tested loop. Syntax of for
loop:
for (Expression 1; Expression 2; Expression 3){
Loop body
}
Q58.What are storage classes?
Ans:A storage class defines the scope (visibility) and life time of variables and/or functions within a C
Program.
There are following storage classes which can be used in a C Program
auto
register
static
extern
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Data Bases
Language Interpreters
Utilities
Q60Expalin C datatypes.
Ans. C has a concept of 'data types' which are used to define a variable before its use. The definition of a
variable will assign storage for the variable and define the type of data that will be held in the location.
The value of a variable can be changed any time.
C has the following basic built-in datatypes.
int
float
double
char
Please note that there is not a boolean data type. C does not have the traditional view about logical
comparison, but thats another story.
int - data type
int is used to define integer numbers.
float - data type
float is used to define floating point numbers.
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage for the number. On PCs
this is likely to be 8 bytes.
char - data type
char defines characters.
Q61.Explain Variables.
Ans. A variable is just a named area of storage that can hold a single value (numeric or character). The C
language demands that you declare the name of each variable that you are going to use and its type, or
class, before you actually try to do anything with it.
The Programming language C has two main variable types
Local Variables
Global Variables
Local Variables
Local variables scope is confined within the block or function where it is defined. Local variables
must always be defined at the top of a block.
When a local variable is defined - it is not initalised by the system, you must initalise it yourself.
When execution of the block starts the variable is available, and when the block ends the variable
'dies'.
Global Variables
Global variable is defined at the top of the program file and it can be visible and modified by any function
that may reference it.
Q62. What are pointers?
Ans. A pointer is a special kind of variable. Pointers are designed for storing memory address i.e. the
address of another variable. Declaring a pointer is the same as declaring a normal variable except you
stick an asterisk '*' in front of the variables identifier.
There are two new operators you will need to know to work with pointers. The "address of"
operator '&' and the "dereferencing" operator '*'. Both are prefix unary operators.
When you place an ampersand in front of a variable you will get it's address, this can be stored in
a pointer vairable.
When you place an asterisk in front of a pointer you will get the value at the memory address
pointed to.
They allow a programmer to say: `this piece of code does a specific job which stands by itself and
should not be mixed up with anyting else',
Second they make a block of code reusable since a function can be reused in many different
contexts without repeating parts of the program text.
Pass by Value: mechanism is used when you don't want to change the value of passed
paramters. When parameters are passed by value then functions in C create copies of the
passed in variables and do required processing on these copied variables.
Pass by Reference mechanism is used when you want a function to do the changes in passed
parameters and reflect those changes back to the calling function. In this case only addresses of
the variables are passed to a function so that function can work directly over the addresses.