Anda di halaman 1dari 11

CDS Questions

1. The C compiler translates source to assembly code in C Programming.


2. The assembler creates object code.
3. What is a C Preprocessor?
Ans C Preprocessor is a program that processes our source program before it is
passed to the compiler.
4. What is the use o! header !iles as used in C programming?
Ans Header files are used to have declarations. It is simple to include a single
header file than writing all the needed functions prototypes.
". What is the Structure o! a C Program?
Ans Documentation Section, in!ing Section, Definition Section, "lobal
declaration Section, main
function, subprogram section.
6. #$ery Program statement in a C program must end %ith a Semicolon.
&. What is the use o! main'( !unction?
Ans main#$ is the starting point of program e%ecution.
). *o% many main'( !unctions can there be in a C Program?
Ans &nly one.
+. What are ,acros?
Ans ' macro is a fragment of code which has been given a name. (henever
the name is used, it is replaced by the contents of the macro. )%ample* +define
,PP)- ./.
-.. What are C To/ens?
Ans 0eywords, Identifiers, Constants, Strings, Special symbols and &perators.
--. What is a constant? What are types o! Constants?
Ans 1here are two types of constants* 2umeric and Character Constants
-0. What is a $ariable?
Ans ' variable is a data name that may be used to store data value.
-3. ,ain '( !unction is a pre de!ined !unction. True or 1alse?
Ans 3alse.
SVIT 1
-2. %hat are the !undamental3Primary Datatypes in C?
Ans integer #int$, character #char$, floating point #float$ and double4precision
floating point #double$.
-". What are user de!ined datatypes?
Ans typedef and enum
-4. What are the operators in C?
Ans 'rithmetic, -elational, ogical, 'ssignment, Increment and Decrement,
Conditional, 5itwise, Special
-&. What are the special operators in C?
Ans comma operator, si6eof operator, pointer operators #7 and 8$ and member
selection operators #and 49$
-). What is si5eo! operator?
Ans It returns the number of bytes the operand occupies.
-+. What is type casting?
Ans converting a variable of one type to another type.
0.. %hat is the !ormat speci!ier !or integer?
Ans :d
0-. 67 is a !ormat speci!ier !or he7adecimal integer.
00. 6o is a !ormat speci!ier !or 8ctal integer.
03. What are control or decision ma/ing statements?
Ans if, switch, conditional operator and goto statements.
02. Synta7 o! conditional operator?
Ans condition? result;* result.. If the condition is true, result; is returned else
result. is returned.
0". What is goto statement?
Ans 1he goto statement is used for unconditional <ump from one part of the
program to another part of the program.
04. What is the di!!erence bet%een %hile and do9%hile?
Ans In case of while loop, the condition is first chec!ed and then the loop is
e%ecuted.
In case of do4while, the loop is first e%ecuted and then the condition is chec!ed.
Here in do4while the loop is e%ecuted atleast once irrespective of the condition.
SVIT 2
0&. What is an array?
Ans 'n array is a group of related data items that share a common name.
0). *o% do you declare an array?
Ans type variable4name=si6e>?
0+. *o% do you initiali5e an array?
Ans static type array4name =si6e>@Alist of valuesB
3.. *o% do you declare an array?
Ans type variable4name=rowCsi6e>=columnCsi6e>?
3-. What is a string in C?
Ans ' string is a collection of character variables.
30. What are the string handling !unctions in C?
Ans strcat'(Dconcatenates two strings, strcmp'( E compares two strings,
strcpy'( E copies one
string over another, strlen'( E finds the length of the string.
33. What are the e7amples o! library !unctions in C?
Ans printf#$ and scanf#$
32. What does :stdio.h; contain?
Ans It contains standard IF& library functions.
3". A main program can contain ho% many !unctions?
Ans It can contain any number of functions.
34. What is a pointer?
Ans ' pointer is a variable, which contains the address of another variable.
3&. What is <=>> pointer?
Ans ' null pointer does not point to any ob<ect.
3). #7plain the scope o! static $ariables.
Ans 1he scope of a static variable is local to the bloc! in which the variable is
defined.
3+. C is *igh le$el >anguage or >o% le$el language?
Ans High4evel anguage.
2.. C programming language is case sensiti$e?
Ans Ges.
2-. What is ?rea/ Statement in C?
SVIT 3
Ans 1he brea/ statement terminates the e%ecution of the current loop and the
Control passes to the statement that follows the terminated statement.
20. What is Continue Statement in C?
Ans (henever a !eyword Hcontinue@ is encountered inside a loop, the control
automatically passes to the beginning of the loop.
23. What is the di!!erence bet%een ?rea/ and Continue in C?
Ans break statement is used to brea! any type of loop such as while, do while
and for loop. Break statement terminates the loop body immediately. Continue
statement is used to brea! current iteration.
'fter continue statement the control returns to the top of the loop test conditions.
22. What is a !unction?
Ans ' function is a self contained bloc! of statements that perform a coherent
tas! of some !ind.
2". Why use !unctions?
Ans It increases the performance of the system.
24. #7plain the use o! !!lush'( !unction.
Ans fflush#$ =returns I if buffer successfully deleted F returns )&3 on an error>
causes the system to empty the buffer associated with the specified output
stream.
2&. #7plain the di!!erence bet%een strcpy'( and memcpy'( !unction.
Ans strcpy#$ copies a string until it comes across the termination character HJIK.
(ith memcopy#$, the programmer needs to specify the si6e of data to be copied.
2). De!ine recursion in C.
Ans ' programming techniLue in which a function may call itself.
2+. What is di!!erence bet%een call by $alue and call by re!erence in
Ans In call by $alue the value to function interchange is passed by value. 'nd
in call by re!erence the address is passed by using symbol H7K and the value is
accessed by using symbol H8K.
".. >ist out di!!erences bet%een arrays and lin/ed list
Ans 1he difference between arrays and lin!ed lists are*
a. 'rrays are linear data structures. in!ed lists are linear and non4
linear data structures.
b. in!ed lists are linear for accessing, and non4linear for storing in
memory
c. 'rray has homogenous values. 'nd each element is independent
of each other positions. )ach node in the lin!ed list is connected
with its previous node which is a pointer to the node.
SVIT 4
d. 'rray elements can be modified easily by identifying the inde%
value. It is a comple% process for modifying the node in a lin!ed list.
e. 'rray elements can not be added, deleted once it is declared. 1he
nodes in the lin!ed list can be added and deleted from the list.
"-. #7plain the term enumerations in C
Ans ' set of named integer constants is !nown as an enumeration. 1he
enumeration type declaration includes the name of the enumeration tag and the
definition of a set of named integers.
)%* enum CI1G AMumbai, 5angalore, Chennai, 2ew DelhiB metros?
"0. What is the use o! typede!?
Ans 1he !eyword typedef is used for defining user defined data types.
"3. *o% to create user de!ined datatypes?
Ans by using the !eyword NtypedefO
Synta%* typedef type identifierA
)%ample* typedef int units?
"2. Bn header !iles %hether !unctions are declared or de!ined?
Ans 3unctions are declared within header file. 1hat is function prototypes e%ist
in a header file,not function bodies. 1hey are defined in library #lib$.
"". What is static memory allocation?
Ans Static ,emory Allocation* Memory is allocated for the declared variable
by the compiler.
"4. What is dynamic memory allocation?
Ans Dynamic ,emory Allocation* 'llocation of memory at the time of
e%ecution #run time$ is !nown as dynamic memory allocation.
"&. What !unctions are used to create dynamic memory allocation?
Ans calloc#$ and malloc#$
"). What is the di!!erence bet%een malloc'( and calloc'(?
Ans malloc#$ is a one argument function while calloc#$ is two argument function
malloc#$ ta!e garbage value at initial time while calloc#$ ta!e null values at initial
time.
"+. What is the purpose o! main' ( !unction?
Ans 1he function main#$ calls F invo!es other functions within it. 1he e%ecution
of the program always starts with main#$ function.
4.. What is the di!!erence bet%een a string and an array?
Ans 1he following are the differences*
SVIT 5
a. String can hold only char data. (here as an array can hold any
data type.
b. 'n array si6e can not be changed. (here as a string si6e can be
changed if it is a char pointer
c. 1he last element of an array is an element of the specific type. 1he
last character of a string is a null EHJIK character.
d. 1he length of an array is to specified in => at the time of declaration
#e%cept char=>$. 1he length of the string is the number of characters
P one #null character$.
4-. Di!!erence bet%een array and pointer?
Ans
Array
i. 'rray allocates space automatically
ii. It cannot be resi6ed
iii. It cannot be reassigned
iv. si6eof #arrayname$ gives the number of bytes occupied by the array.
Pointer
;4)%plicitly assigned to point to an allocated space.
.4It can be si6ed using realloc#$
Q4pointer can be reassigned.
R4si6eof #p$ returns the number of bytes used to store the pointer variable p
40. What are the uses o! a pointer?
Ans Pointer is used in the following cases
;. It is used to access array elements
.. It is used for dynamic memory allocation.
Q. It is used in Call by reference
R. It is used in data structures li!e trees, graph, lin!ed
list etc.
/.
43. What is a structure?
Ans Structure constitutes a super data type which represents several different
data types in a single unit. ' structure can be initiali6ed if it is static or global.
42. What is a union?
Ans ,nion is a collection of heterogeneous data type but it uses efficient
memory utili6ation techniLueby allocating enough memory to hold the largest
member. Here a single area of memory contains values of different types at
different time. ' union can never be initiali6ed.
4". What are the di!!erences bet%een structures and union?
Ans ' structure variable contains each of the named members, and its si6e is
large enough to hold all the members. Structure elements are of same si6e. '
union contains one of the named members at a given time and is large enough to
hold the largest member. ,nion element can be of different si6es.
SVIT 6
44. What are the di!!erences bet%een structures and arrays?
Ans Structure is a collection of heterogeneous data type but array is a collection
of homogeneous data types.
Array
;4It is a collection of data items of same data type.
.4It has declaration only
Q4.1here is no !eyword.
R4 array name represent the address of the starting element.
Structure
;4It is a collection of data items of different data type.
.4 It has declaration and definition
Q4 !eyword struct is used
R4Structure name is !nown as tag it is the short hand notation of the
declaration.
4&. What are enumerations?
Ans 1hey are a list of named integer4valued constants. )%ample*enum color
A blac! , orange@R,yellow, green, blue, violet B?1his declaration defines the
symbols Nblac!O, NorangeO, NyellowO, etc. to have the values N;,O NR,O N/,O S etc.
1he difference between an enumeration and a macro is that the enum actually
declares a type, and therefore can be type chec!ed.
4). Di!!erentiate bet%een !or loop and a %hile loop? What are it uses?
Ans 3or e%ecuting a set of statements fi%ed number of times we use for loop
while when the number of iterations to be performed is not !nown in advance we
use while loop.
4+. What the ad$antages o! using =nions?
Ans (hen the C compiler is allocating memory for unions it will always reserve
enough room for the largest member.
&.. What is the di!!erence bet%een Strings and Arrays?
Ans String is a seLuence of characters ending with 2, .it can be treated as a
one dimensional array of characters terminated by a 2, character.
&-. Bn CC %hy is the $oid pointer use!ul? When %ould you use it?
Ans 1he void pointer is useful because it is a generic pointer that any pointer
can be cast into and bac! again without loss of information.
&0. What is a <=>> Pointer? Whether it is same as an uninitiali5ed
pointer?
Ans 2ull pointer is a pointer which points to nothing but uninitiali6ed pointer may
point to anywhere.
&3. Are pointers integer?
SVIT 7
Ans 2o, pointers are not integers. ' pointer is an address. It is a positive
number.
&2. Can a Structure contain a Pointer to itsel!?
Ans Ges such structures are called self4referential structures.
&". Di!!erence bet%een synta7 $s logical error?
Ans
Synta7 #rror
;41hese involves validation of synta% of language.
.4compiler prints diagnostic message.
>ogical #rror
;4logical error are caused by an incorrect algorithm or by a statement mistyped in
such a way
that it doesnKt violet synta% of language.
.4difficult to find.
&4. What is pre9increment and post9increment?
Ans PPn #pre increment$ increments n before its value is used in an assignment
operation or any e%pression containing it. nPP #post increment$ does increment
after the value of n is used.
&&. What is a !ile?
Ans ' file is a region of storage in hard dis!s or in au%iliary storage devices.It
contains bytes of
information .It is not a data type.
&). What are the types o! !ile?
Ans 3iles are of two types
;4high level files #stream oriented files$ *1hese files are accessed using library
functions
.4low level files#system oriented files$ *1hese files are accessed using system
calls
&+. What is 1B>#?
Ans 3I) is a predefined data type. It is defined in stdio.h file.
).. What is a !ile pointer?
Ans 1he pointer to a 3I) data type is called as a stream pointer or a file
pointer. ' file pointer points to the bloc! of information of the stream that had <ust
been opened.
)-. Di!!erence bet%een an array o! pointers and a pointer to an array?
Ans
Array o! pointers
i. Declaration is* dataCtype 8arrayCname=si6e>?
SVIT 8
.4Si6e represents the row si6e.
Q4 1he space for columns may be dynamically
Pointers to an array
;4Declaration is dataCtype # 8arrayCname$=si6e>?
.4Si6e represents the column si6e.
)0. Are the $ariables argc and arg$ are al%ays local to main?
Ans Ges they are local to main.
)3. Can main '( be called recursi$ely?
Ans Ges any function including main #$ can be called recursively.
)3.What are the stages o! de$eloping your C program?
Ans 1here are four stages of developing C program
Creating the program
Compiling the program
in!ing the program with functions that are needed from C ibrary
-unning the program.
)2. What are the storage classes in C?
Ans auto, static, e%tern and register.
)". What are the compile time operators?
Ans only si6eof is a compile time operator.
)4. What are the storage classes in C?
Ans auto, static, e%tern and register.
)&. What are the compile time operators?
Ans only si6eof is a compile time operator.
)). Bncase o! !or'( loopC initiali5ation is mandatory. True or !alse?
Ans 3alse.
)+. Bncase o! !or'( loopC test9condition is mandatory. True or !alse?
Ans 1rue.
+.. What is :ctype.h ; used !or?
Ans Character testing and conversion functions
+-. C !ollo%s Top do%n Approach.
+0. #7plain the di!!erence bet%een e7it'( and De7it'( !unction.
Ans e%it#$ does cleanup wor! li!e closing file descriptor, file stream and so on,
while Ce%it#$ does not.
SVIT 9
+3. What are $olatile $ariables?
Ans Tolatile variables are li!e other variables e%cept that the values might be
changed at any given point of time only by Hsome e%ternal resourcesK.
+2. What does static $ariable mean in C?
Ans static is an access Lualifier that limits the scope but causes the variable to
e%ist for the lifetime of the program.
+". 8ut o! !gets'( and gets'( %hich !unction is sa!e to use and %hy?
Ans fgets#$ is safer than gets#$, because we can specify a ma%imum input
length. 2either one is completely safe, because the compiler canKt prove that
programmer wonKt overflow the buffer he pass to fgets #$.
+4. What do the Ec@ and E$@ in argc and arg$ stand !or?
Ans 1he c in argc#argument count$ stands for the number of command line
argument the program is invo!ed with and v in argv#argument vector$ is a pointer
to an array of character string that contain the arguments.
+&. What is the di!!erence bet%een a Stac/ and an Array?
Ans STACF
i$ Stac! is a ordered collection of items
ii$ Stac! is a dynamic ob<ect whose si6e is constantly changing as items are
pushed and popped .
iii$ Stac! may contain different data types
iv$ Stac! is declared as a structure containing an array to hold the element of
the stac!, and an integer to indicate the current stac! top within the array.
AGGAH
i$ 'rray is an ordered collection of items
ii$ 'rray is a static ob<ect i.e. no of item is fi%ed and is assigned by the
declaration of the array
iii$ It contains same data types.
iv$ 'rray can be home of a stac! i.e. array can be declared large enough for
ma%imum si6e of the stac!.
+). What actions are per!ormed %hen a !unction is called?
Ans (hen a function is called
i$ arguments are passed
ii$ local variables are allocated and initiali6ed
ii$ transferring control to the function.
++. What do you mean by garbage collection?
Ans It is a techniLue in which the operating system periodically collects all the
deleted space onto the free storage list. It ta!es place when there is minimum
amount of space left in storage list or when CP, is ideal. 1he alternate method to
this is to immediately reinsert the space into free storage list which is time
consuming.
SVIT 10
-... What is a !lo% chart?
Ans ' flowchart is a type of diagram that represents an algorithm or process,
showing the steps as bo%es of various !inds, and their order by connecting these
with arrows.
SVIT 11

Anda mungkin juga menyukai