Computer Concepts Programming

Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

Computer Programming (ECS-201)

Multiple Choice Questions1) The C language consists of ____ number of keywords.


A] 32
B] 40
C] 24
D] 56
2) Which of the following is a keyword used for a storage class?
A] Printf
B] externa
l C] auto
D] scanf
3) The prototype of the function in the header file isA]Stdio.h
B] stdlib.h
C] conio.h
D] io.h
4) Preprocessor Directives are used for A] Macro Expansion
B] File Inclusion
C] Conditional Compilation
D] All of these
5) Which operator has the lowest priority ?
A] ++
B] %
C] +
D] ||
6) The type cast operator isA] (type)
B] cast()
C] //
D]
7) File manipulation functions in C are available in which header file ?
A] streams.h
B] stdio.h
C] stdlib.h
D] files.h
8) Which pair of functions below are used for single xharacter I/O ?
A] getchar() and putchar()
B] scanf() and printf()
C] input() and output()
D] Non of these
9) Which function is used to read character as you type ?
A] getchar()
B] getch()

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 + +;

printf ( \n %s, a); }


A] Error
B] INFO
C] NFO
D] None of these
17) Which of the following operator has right to left associativity?
A] &&
B] //
C] %
D] sizeof
18) What wiil be the output ?
Void main ( ) {
IntI ;
I=0x10+ 010+10;
Printf (\nx=%x, i); }
A] x= 34
B] i= 34
C] I = 22
D]Error

19) Explicit type conversion is known as


A] conversion
B] disjunction
C] separation
D] casting
20) What will be the output ?
#define SQUARE(X) X * X
void main ( ) {
printf (\n Square = %d , SQUARE(10+2) ); }
A] Square = 144
B] Square =32
C] Square =122
D]Square =12
21) By default a function returns a value of type
A] int
B] char
C] void
D] None of these
22) What will be the value of x after executing the program ?
void main ( ) {
int x;
x = printf(I See, Sea in C);
printf(\n x= % d , x); }
A] x= 15
B] x=2
C] Garbage value
D] Error

23) What is sizeof In C ?


A] Operator
B] Reserve Word
C] Both (A) and (B)
D] Function
24) Study the following C program
Void main ( ) {
Int a= 0;
For ( ; a ;);
A++; }
What will be the value of the variable a, on the execution of the above program
A] I B] 0 C] 1 D] None of these
25) Which is not keyword in C ?
A]typedef B] const C] near D] complex
26) What will be the output of the following program code ?
void main ( ) {
char a[]= Hello World ;
char *p ;
p=a;
printf(\n%d%d%d%d,sizeof(a), sizeof(p), stren (a), strlen(p) ); }
A] 11 11 10 10 B] 10 10 10 10 C] 12 12 11 11 D] 12 2 11 11
27) The meaning of arrow operator in a->b
A] ( *a).b B] a.(*b) C] a.b D] None of these
28) What will be the output of the following program code?
Void main ( ) {
Printf (\n ABC\b\b\bInfo World); }
A] Info world B] ABC Info world C] strxfrm D] strcut
29) Which is valid string function ?
A] strpbrk B] strlen C] strxfrm D] strcut
30) What will be the size of following structure?
Struct sample {
Static int x;
inty,z; } ;
A]6 bytes B] 2 bytes C] + bytes D] None of these
31) Which of the following function not convert floating point number to string ?
A] fcvt B] gevt C] eevt D] hcvt
32) What will be the output ?
void main ( ) {
printf(%d,B < A ); }
A] Error B] 1 C] 0 D] None of these
33) Which one of the following is condirionaldirective ?
A] #nifdefn B] #ifdefn C] # ifdefn D] #nifdef
34) What will be the output ?

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

74) The operator / can be applied to


A] integer values B] float values C] double values D] All of these
75) The equality operator is represented by
A] := B] .EQ. C] = D]==
76) Operators have hierarchy. It is used to know which operator
A] is most important B] is used first C] is faster D] operates on
large numbers
77) The bitwise AND operator is used for
A] Masking B] Comparison C] Division D] Shifting bits
78) The bitwise OR operator is used to
A] set the desired bits to 1 B] set the desired bits to 0 C] divide
Numbers
D] multiply numbers
79) Which of the following operator has the highest precedence?
A ] * B] == C] => D] +
80) The associativity of !operator is
A] Right to Left B] Left to Right C] (a) for Arithmetic and (b) for Relational
D] (a) for Relational and (b) for Arithmetic
81) Which operator has the lowest priority?
A]++ B]% C]+ D]||
82) Which operator has the highest priority?
A]++ B]% C]+ D]||
83) Operators have precedence. A Precedence determines which
operator is
A]faster B] takes less memory C] evaluated first D]takes no
Arguments
84) Integer Division results in
A] Rounding the fractional part B] truncating the fractional part
C] Floating value D]An Error is generated
85) . Which of the following is a ternary operator?
A] ? B] * C] sizeof D]^
86) What will be the output of the expression 11 ^ 5?
A]5 B]6 C] 11 D]None of these
87) The type cast operator is
A] (type) B]cast() C]// D] " "
88) Explicit type conversion is known as
A] Casting B] Conversion C] Disjunction D] Separation
89) The operator + in a+=4 means
A] a = a + 4 B] a + 4 = a C] a = 4 D] a = 4 + 4

90) p++ executes faster than p+1 because


A] p uses registers B] p++ is a single instruction C] ++ is faster
than +
D] None of these
91) Which of the following statements is true?
A] C Library functions provide I/O facilities B] C inherent I/O
facilities
C] C doesnt have I/O facilities D] Both (a) and (c)
92) Header files in C contain
A] Compiler commands B] Library functions C] Header
information of C
programs D] Operators for files
93) Which pair of functions below are used for single character I/O.
A] Getchar() and putchar() B] Scanf() and printf() C] Input() and
output()
D] None of these
94) The printf() function retunes which value when an error occurs?
A]Positive value B]Zero C] Negative value D]None of these
95) Identify the wrong statement
A] putchar(65) B] putchar('x') C] putchar("x") D] putchar('\n')
96) Which of the following is charecter oriented console I/O
function?
A] getchar() and putchar() B] gets() and puts() C]scanf() and
printf()
D] fgets() and fputs()
97) The output of printf("%u", -1) is
A] -1 B] minimum int value C] maxiumint value D] Error message
98) An Ampersand before the name of a variable denotes
A] Actual Value B] Variable Name C] Address D] Data Type
99) Symbolic constants can be defined using
A] # define B] const C] symbols D] None of these
100) Null character is represented by
A] \n B] \0 C] \o D] \e
101) Which header file is essential for using strcmp() function?
A] string.h B] strings.h C] text.h D] strcmp.h
102) malloc() function used in dynamic allocation is available in
which header file?
A] stdio.h B] stdlib.h C] conio.h D] mem.h
103) File manipulation functions in C are available in which header
file?
A] streams.h B] stdio.h C] stdlib.h D] files.h
104) C supports how many basic looping constructs

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

126) Maximum number of elements in the array declaration int


a[5][8] is
A ] 28 B] 32 C] 35 D] 40
127) If the size of the array is less than the number of initializers
then,
A ] Extra values are being ignored
B ] Generates an error message
C ] Size of Array is increased
D ] Size is neglected when values are given
128) Array subscripts in C always start at
A ] -1 B] 1 C] 0 D] Value provided by user
129) A Structure
A ] can be read as a single entity

B ] cannot be read as a single entity


C ] can be displayed as a single entity
D ] has member variables that cannot be read individually
130) Identify the invalid pointer arithmetic
A] Addition of float value to a pointer
B] Comparision of pointers that do not point to the element of the
same array
C] Subtracting an integer from a pointer
D] Assigning the value 0 to a pointer variable

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?

43. What is use of return statement?


44. What is the use of strcat() function?
45. What is the use of strcmp() function?
46. What is the use of strrev() function?
47. What is the use of strlen() function?
48. What is the use of strcpy() function?
49. What is recursive function?
50. What do you mean by call by value?
51. What do you mean by call by reference?
52. What is pointer?
53. What is structure?
54. What is main difference between structure and union?
55. What is use of typedef?
56. Whether Structured programming helps in reducing errors?
57. What is preprocessor ?
58. Give any two features of preprocessor
59. Give the syntax for defining File
60. Give the syntax for opening File
61. Give the syntax for Closing File
62. What is fopen()?
63. What is fclose()?
64. What is the use of ftell()?
65. What is the use of fseek()?
66. What is the use of rewind()?
67. What is the use of feof()?
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.

Enlist the features of C.


Explain different data types used in C language?
Explain type identifiers in C?
Explain in brief structure of C programming?
5.What is operator enlist all operators used in C?
What is data type explain the any four data types used in C language?
Explain the difference between = and == operator explain with
example?
Write a short note precedence & order of evaluation?
Differentiate between relational and logical operators used in C?
Write short note on Input & Output functions used in C (i.e. print &scanf functions?
What is variable? What are the rules for defining variables?
Differentiate between local variable and global variable?
Explain symbolic constants used in C?
Explain any two bitwise operator with suitable example.Explain with example ++i and i++.
Explain logical operators and expressions used in C?
Explain the following g functions
a. i)getch() and ii) clrscr()
Explain printf() and scanf() function with an example
Explain syntax and use of Do__While statement
Which looping statements does C provides?Explain any one.
Explain continue and break statements with the help of example.
Explain switch statement with its syntax and example.
Expalin the difference between swith and nested if else with an example?
What is array? How to declare array?Explain with suitable example.
Expalin one dimensional array with an example
Explain Two dimensional array with an example.Explain applications of array.

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.

Explain any 4 string functions with suitable example?


What is the difference between call by value and call by Reference?
What is recursion explain with suitable example.
Explain Automatic , Static and register storage classs.
Explain Extern storage class.
For what purpose \0 is used in string operations explain with suitable example.
What is function ?how function is defined.
Explain the difference between calling function and called function? Explain void function?
Explain what is pointer?expalin with suitable example. Explain pointer to structure in detail.
Explain pointer to function in detail.
Explain how to access a value using pointer?give a suitable example.
Write a short note on pointer to pointer
Distinguish bet malloc and calloc()
What is structure?explain with suitable example. Explain array of structure with example
Explain Nested structure with example.
Describe programming approach. Explain the use of Typedef
Explain directives. Explain features of preprocessors
What is a pre-processor explain #include ,#define
Explain 1)fprintf() ii)fscanf() . Write a short note on file handling in C
Explain the following i)rewind ii)feof
Distinguish between the following
getch and getc
putch and putc
putc and getc
What is command line argument? Explain command line argument with example
What is macro? Explain with example
Differentiate between if-else-if and switch statement.
Explain function with argument and return type.
Explain array of pointers.
Explain dynamic memory allocation in brief.
Explain pointer to structure.
82. Explain the following types of file
i)Sequential
ii)Index Sequential
iii)Direct File
What is advantage of representing an array of string by an array of pointer to string.
Explain the following functions with example
1)getchar() 2)putchar()
Explain the following functions with example
1)getche() 2)putche()
Explain sizeof operator with example.
Explain conditional operator with example.
What is user defined functions and built-in functions.Enlist them.
What is null string ?What is its length?
What are static variable? Compare with standard local variable.
Write a rule for declaring character constant.
Explain * operator and & operator with example.
What are the rule of to use period(.) operator.
What is EOF and what value does usually have ?
What are identifier and keywords? Explain it with suitable example.
What is type casting? Explain it with suitable example.
What is swaping? Explain it with suitable program without using third variable.
Write a short note on ternary operator and cast operator.
What is string constant?How is string constant is differ from character constant?
List out the five arithmetic operators in C.
What is the associtivity rules involve in this operator.

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

Q2.What is an algorithm? Explain.


Ans. An Algorithm is a step wise analysis of the work to be done.
Eg: An algorithm to determine a students final grade and indicate whether it is passing or failing.
The final grade is calculated as the average of four marks.
Step 1: Input m1,m2,m3,m4
Step2: Grade (m1+m2+m3+m4)/4
Step3: if Grade<50 then
Print fail
else
Print pass
endif

Q3. Explain the basic operations of computer?


Ans.

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.

Q6.What is a software ? How do you classify sofftware?

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

Q8. What are the basic data types used in C?


Ans.

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

Q10.WAP to accept four numbers andcompute their sum,per,grade and average.


Ans.

#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();
}

Q11.WAP to wheather the year is Leap year or not.


Ans.

#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();
}

Q.12 WAP to print wheather the number is even or odd.


Ans.

#include<stdio.h>
#include<conio.h>
voidmain()
{
int num;
clrscr();
scanf(%d,&num);
if(num%2==0)
printf(numiseven);
else
printf(numberisodd);
getch();
}

Q13.WAP to print factorial of any number.


Ans.

#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();
}

Q.14 WAP to print the sum of digits of any number.


Ans.

#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

Q15.WAP to find largest among three numbers.


Ans.

#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();
}

Q.16 WAP to print wheather the number is even or odd.


Ans.

#include<stdio.h>
#include<conio.h>
voidmain()
{
int num;
clrscr();
scanf(%d,&num);
if(num%2==0)
printf(numiseven);
else
printf(numberisodd);
getch();
}

Q.17 WAP to print numbers from 1 to 10 sing while loop.


Ans.

#include<stdio.h>
#include<conio.h>
voidmain()
{
int i=1;
while(i<=10)
{
printf(%d,i);
i=i+1;
}
getch();
}

Q.18 WAP to print numbers in reverse order with a differences of 2.


Ans.

#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

It refers to name of variable,function and Array.


These are User defined Names.
It starts from alphabet.
Both Upper and Lower case letters are permitted.
Generally lower case letter are commonly used.
The underscore character is also permitted in identifier.
It is usually used as link b/w two word in long identifier.

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);
}

Q25. WAP to find the largest of two numbers using functions.


Ans.
#include<stdio.h>
#include<conio.h>
int larger(int x,int y);
void main()
{
int a,b,l;
printf(%d%d,&a,&b);
l=larger(a,b);
getch();
}
int larger(int x,int y)
{
if(x>y)
return x;
else
return y;
}
Q26.What is pointers. Why are they needed?
Ans. Pointers contain address of a variable that has a specific value.
Pointer declaration
* used with pointer variables
int *myPtr;
Declares a pointer to an int (pointer of type int *)
Multiple pointers require using a * before each variable declaration
int *myPtr1, *myPtr2;
Can declare pointers to any data type
Initialize pointers to 0, NULL, or an address
0 or NULL points to nothing (NULL preferred)
Q27.What is a preprocessor? Also explain its features.
Ans. Pre-processor is a program that processes the source code before it passes through the compiler .

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.
5. Main functions performed by preprocessor directives are1.Simpe macro substitution
2.Macro with arguments
3.Conditional compilation
Q28.What is a macro? What points should be taken into consideration while defining macros?
Ans. #define macro_name macro_expansion
Here macro_name is any valid C identifier and it is generally taken in capital letters to distinguish
it from other variables.
Macro_expansion can be any text.
A space is necessary between macro_name and macro_expansion.
Pre-processor replaces all the occurrence of macro_name with the macro_expansion.
For example
#define PI 3.14
#define MAX 100
Pre-processor searches for the macro_name in the source code and replaces it with macro
expansion.
For wherever the macro name PI appears in the code,it is replaced by 3.14
Q29.Differentiate between macro and functions.

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

Outside of any function always static


int A[13];
#define CLASS_SIZE 73
double B[CLASS_SIZE];
const int nElements = 25
float C[nElements];

Q31.What is structure?.How does a structure differ from an array?


Ans.A structure contain a number of data types together. These data types may or may not be of same
type. Thus a structure gathers together, different types of data to comprise a given entity.
Consider the following structure:
Struct book
{
char name[10];
float price;
int pages;
};
Struct book b1,b2,b3;
b1 is a structure element of type book therefore it has a single entity in memory. The elements of b1 can
be accesed by using dot operator.
On the other hand array is a collection of similar elements. Similar elements of array can be all int or all
float etc but not be the combination of various data type. The elements of array can be accessed by sing
suffix with array name.

Q32.Write a program to find the size of a pointer.


Ans.#include<stdio.h>
main()
{
int *iptr;
int *cptr;
int s1, s2;
s1=size of(iptr);
s2=size of(cptr);
clrscr();
printf(size of iptr=%d\n,s1);
printf(size of cptr=%d\n,s2);
getch();
return 0;
}
OUTPUT-size of iptr=2
Size of cptr=2
Wheather the pointer is point to an int,a float, a char or long type of objects,the size of the pointer is
always 2 bytes.
Q33.Explain the rules of pointer arithmetic.

Ans. Declaration of pointer:


1-An integer number can be added to pointer.
2- An integer number can be substracted to pointer.
3- Substraction of one pointer from other pointer.
4- Two pointer can be compared
5- Two pointer can not be added.
6- Pointers can nt be multiplied with a constant value.
7- Pointer can not be divided with a constant value.
8- Pointer always increments or decrements to it,s own type.
Q34. Write a program to check whether the number is prime or not.
Ans. #include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,num,flag=1;
clrscr();
scanf("%d",&num);
for(i=2;i<sqrt(num);i++)
{
if(num%i==0)
{
printf("no. not prime");
flag=0;
break;
}
}
if(flag==1)
printf("num prime");
getch();
}
Q36. WAP to print the first n terms in Fibonacci series.
Ans. /*WAP to print finonacci series*/
#include<stdio.h>
#include<conio.h>
void main()
{
int x=1,y=1,z;
clrscr();
printf(%d %d,x,y);
for(i=1;i<10;i++)
{
z=x+y;
printf(%d,z);
x=y;
y=z;
}
getch();
}
Q37. Write a program to check whether the number is palindrome or not.

#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();
}

Q41. WAP to print the sum of x+x^2+x^3+...


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,sum=0,x;
clrscr();
printf("enter the value of x:");
scanf("%d",&x);
for(i=1;i<=3;i++)
sum=sum +pow(x,i);
printf("sum=%d",sum);
getch();
}
Q42. WAP to print the sum of series 1/1!+2/2!+3/3!+...
#include<stdio.h>
#include<conio.h>
void main()
{
float i=1,j,fact;
float sum=0;
clrscr();
while(i<=7)
{
fact=1;
for(j=1;j<=i;j++)
fact=fact*j;
sum=sum+i/fact;
i++;
}
printf("\n%f",sum);
getch();
}
Q43. WAP to multiply two matrices .
#include<stdio.h>
#include<conio.h>
#define ROW1 2
#define COL1 3
#define ROW2 COL1
#define COL2 3
void main()
{
int mat1[ROW1][COL1],mat2[ROW2][COL2],mat3[ROW1][COL2];
int i,j,k;
printf("enter the values for matrix1:");
for(i=0;i<ROW1;i++)

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();
}

Q45. Write a program to find minimum and maximum number in an array .


#include<stdio.h>

#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();
}

Q47. Write a program for addition of two matrix .


#include<stdio.h>
#include<conio.h>
#define ROW 2
#define COL 3
void main()
{
int mat1[ROW][COL],mat2[ROW][COL],mat3[ROW[COL];
int i,j;
printf("enter the values for matrix1:");
for(i=0;i<ROW;i++)
for(j=0;j<COL;j++)
scanf("%d",&mat1[i][j]);
printf("enter the values for matrix2:");
for(i=0;i<ROW;i++)

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

Defines a macro substitution

#undef

Undefines a macro

#include

Specifies the files to be included

#ifdef

Test for macro definition

#endif

Specifies the end of #if

#ifndef

Test whether the macro is not defined

#if

Test a compiler time condition

Q49.WAP to display the values of structure using arrays.


Ans.#include<stdio.h>
#include<conio.h>
struct student{
char name[20];
int rollno;
float marks;
};
void main()
{
struct student stu[10];
int i;
for(i=0;i<10;i++)
{
printf(enter the value);
scanf(%s%d%f,stu[i].name,&stu[i].rollno,stu[i].marks);
}
for(i=0;i<10;i++)
printf(%s%d%f,stu[i].name,stu[i].rollno,stu[i].marks);
getch();
}
Q50. WAP to print the sum of digits of any number.
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int num, sum=0,rem;
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf(sum of digits=%d,sum);
getch();
}

Q51. What do you understand by operator precedence and associativity?


Ans.
Operator precedence determines which operator will be performed first in a group of operators
with different precedence. For instance 5 + 3 * 2 is calculated as 5 + (3 * 2), giving 11, and not as (5 + 3) *
2, giving 16.
The operator associativity rules define the order in which adjacent operators with the same precedence
level are evaluated. For instance the expression 8 - 3 - 2 is calculated as (8 - 3) - 2, giving 3, and and not
as 8 - (3 - 2), giving 7. In this case we say that subtraction is left associative meaning that the left most
subtraction must be done first.
Q52.

What do you understand by hardware and software?

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.

Write the difference between compiler and interpreter?

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.

int i= 0; // definition and initialization of i


int j; // just a definition of j
j= i; // assignment of j

Q55.Write short note on bitwise operators.


Ans:Bitwise operator works on bits and perform bit by bit operation.
Assume if A = 60; and B = 13; Now in binary format they will be as follows:
A = 0011 1100
B = 0000 1101
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
Show Examples
There are following Bitwise operators supported by C language
Operator

Description

Example

&

Binary AND Operator copies a bit to the


result if it exists in both operands.

(A & B) will give 12 which is 0000 1100

Binary OR Operator copies a bit if it exists in


eather operand.

(A | B) will give 61 which is 0011 1101

Binary XOR Operator copies the bit if it is set


in one operand but not both.

(A ^ B) will give 49 which is 0011 0001

Binary Ones Complement Operator is unary


and has the efect of 'flipping' bits.

(~A ) will give -60 which is 1100 0011

<<

Binary Left Shift Operator. The left operands


value is moved left by the number of bits
specified by the right operand.

A << 2 will give 240 which is 1111 0000

>>

Binary Right Shift Operator. The left


operands value is moved right by the
number of bits specified by the right
operand.

A >> 2 will give 15 which is 0000 1111

Q56.What do you understand by OS?What are the classifications of OS?


Ans. Classification of Operating System.
Multi user. Multi user operating systems allow two or more users to run programs at the same time. Some
operating systems permit hundreds or even thousands of concurrent users. The operating systems of
mainframes and minicomputers are multi user system.
Multiprocessing. Multiprocessing refers to a computer system ability to support more than one process at
the same time. Multiprocessing operating systems enable several programs to run concurrently. MVS and
UNIX are two of the most widely used multiprocessing systems, but there are many others, including
OS/2 for high end PCs.
Multitasking. Multitasking allows more than one program one program to run concurrently. Multitasking is
the ability to execute more than one task at the same time, a task being a program. The terms
multitasking and multiprocessing are often used interchangeably, although multiprocessing sometimes
implies that more then one CPU is involved.
Multithreading. Multithreading allows different parts of a single program to run concurrently.
Multithreading is the ability of an operating system to execute different parts of a program called threads,
simultaneously.
Real time. Real time operating system is systems that respond to input immediately. This category
includes operating systems designed substantially for the purpose of controlling and monitoring external
activities with timing constraints. They are used for such tasks as navigation, in which the computer must
react to a steady flow of new information without interruption.
Q57.Explanation of loops or looping in c programming language by examples and questions

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

auto - Storage Class


auto is the default storage class for all local variables.
register - Storage Class
register is used to define local variables that should be stored in a register instead of RAM. This means
that the variable has a maximum size equal to the register size (usually one word) and cant have the
unary '&' operator applied to it (as it does not have a memory location).
Register should only be used for variables that require quick access - such as counters. It should also be
noted that defining 'register' goes not mean that the variable will be stored in a register. It means that it
MIGHT be stored in a register - depending on hardware and implimentation restrictions.
static - Storage Class
static is the default storage class for global variables. The two variables below (count and road) both have
a static storage class.
static variables can be 'seen' within all functions in this source file. At link time, the static variables defined
here will not be seen by the object modules that are brought in.
static can also be defined within a function. If this is done the variable is initalised at run time but is not
reinitalized when the function is called. This inside a function static variable retains its value during
vairous calls.
extern - Storage Class
extern is used to give a reference of a global variable that is visible to ALL the program files. When you
use 'extern' the variable cannot be initalized as all it does is point the variable name at a storage location
that has been previously defined.
When you have multiple files and you define a global variable or function which will be used in other files
also, then extern will be used in another file to give reference of defined variable or function. Just for
understanding extern is used to decalre a global variable or function in another files.
Q59.Why to use C ?
Ans C was initially used for system development work, in particular the programs that make-up the
operating system. C was adoped as a system development language because it produces code that runs
nearly as fast as code written in assembly language. Some examples of the use of C might be:

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.

Q63. What is void pointer?


Ans:It is also called as Generic Pointer( void Pointer ).When a variable is declared as being a pointer to
type void it is known as a generic pointer. Since you cannot have a variable of type void, the pointer will
not point to any data and therefore cannot be dereferenced. It is still a pointer though, to use it you just
have to cast it to another kind of pointer first. Hence the term Generic pointer. This is very useful when
you want a pointer to point to data of different types at different times.
Q64.What are functions? How to pass parameters in functions?
Ans: A function is a module or block of program code which deals with a particular task. Making functions
is a way of isolating one block of code from other independent blocks of code.
Functions serve two purposes.

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.

Passing Parameters to a Function


There are two ways to pass parameters to a function:

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.

Q65. What are the different built-in string functions?


Ans. String Manipulation Functions

Strcpy:copy source string to destination string


strncpy: first n characters of string2 to stringl .
strcmp:Compare string1 and string2 to determine alphabetic order.
strncmp: Compare first n characters of two strings.
Strlen:Determine the length of a string.
Strcat: Concatenate string src to the string dest.
Strncat:Concatenate n chracters from string src to the string dest.
Strchr:Find first occurrence of character c in string.
strrchr:Find last occurrence of character c in string.
Strstr :Find first occurrence of string string1 in string2.
Strtok: Parse the string s into tokens using delim as delimiter.

You might also like