C Programming Interview Question and Answer SET 8
141.
Do you know, what is the meaning and use of static keyword in c?
Keyword
static is used for declaring static variables in c. This modifier is used with
all data types like int, float, double, array, pointer, structure, function
etc.
142.
What is difference between .com program and .exe program?
Both
.com and .exe program are executable program but .com program execute faster
than .exe program. All drivers are .com program. .com file has higher
preference than .exe For example:
143.
Difference between TSR and TSO program
TSO
means terminate but stay outside. It is that program, which release the main
memory after the execution of the program. Example ms paint, notepad, turbo c
compilers etc.
TSR
means terminate but stay residence .It is those program, which after the
execution of the program does not release the RAM (main memory).e.g. antivirus.
144.
Describe turbo c compiler?
Turbo
c is an IDE of c programming language created by Borland. Turbo C 3.0 is
based on MS DOS operation system. It is one of the most popular c
compilers. It uses 8086 microprocessor which is 16 bit microprocessor. It has
20 address buses and 16 data bus. Its word length is two byte.
145.
Out of fgets() and gets() which function is safe to use and why?
fgets()
is safer than gets(), because we can specify a maximum input length. Neither
one is completely safe, because the compiler can’t prove that programmer won’t
overflow the buffer he pass to fgets ().
146.
Difference between strdup and strcpy?
Both
copy a string. strcpy wants a buffer to copy into. strdup allocates a buffer
using malloc().
Unlike strcpy(), strdup() is not specified by ANSI .
Unlike strcpy(), strdup() is not specified by ANSI .
147.
Differentiate between a for loop and a while loop? What are it uses?
For
executing a set of statements fixed number of times we use for loop while when
the number of
iterations to be performed is not known in advance we use while loop.
iterations to be performed is not known in advance we use while loop.
148.
What is storage class? What are the different storage classes in C?
Storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage. The storage classes in c are auto, register, and extern, static, typedef.
Storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage. The storage classes in c are auto, register, and extern, static, typedef.
149.
What are the uses of a pointer?
(i)It
is used to access array elements
(ii)It is used for dynamic memory allocation.
(iii)It is used in Call by reference
(iv)It is used in data structures like trees, graph, linked list etc.
(ii)It is used for dynamic memory allocation.
(iii)It is used in Call by reference
(iv)It is used in data structures like trees, graph, linked list etc.
150.In
header files whether functions are declared or defined?
Functions
are declared within header file. That is function prototypes exist in a header
file,not function bodies. They are defined in library (lib).
151.
Difference between pass by reference and pass by value?
Pass
by reference passes a pointer to the value. This allows the callee to modify
the variable directly.Pass by value gives a copy of the value to the callee.
This allows the callee to modify the value without modifying the variable. (In
other words, the callee simply cannot modify the variable, since it lacks a
reference to it.)
152.
What are enumerations?
They
are a list of named integer-valued constants. Example:enum color { black ,
orange=4,yellow, green, blue, violet };This declaration defines the symbols
“black”, “orange”, “yellow”, etc. to have the values “1,” “4,” “5,” … etc. The
difference between an enumeration and a macro is that the enum actually
declares a type, and therefore can be type checked.
153.
Are pointers integer?
No,
pointers are not integers. A pointer is an address. It is a positive number.
154.
What is static memory allocation?
Compiler
allocates memory space for a declared variable. By using the address of
operator, the reserved address is obtained and this address is assigned to a
pointer variable. This way of assigning pointer value to a pointer variable at
compilation time is known as static memory allocation.
155.
What is dynamic memory allocation?
A
dynamic memory allocation uses functions such as malloc() or calloc() to get
memory dynamically. If these functions are used to get memory dynamically and
the values returned by these function are assigned to pointer variables, such a
way of allocating memory at run time is known as dynamic memory allocation.
156.
What modular programming?
If
a program is large, it is subdivided into a number of smaller programs that are
called modules or subprograms. If a complex problem is solved using more
modules, this approach is known as modular programming
157.
What is a function?
A
large program is subdivided into a number of smaller programs or subprograms.
Each subprogram specifies one or more actions to be performed for the larger
program. Such sub programs are called functions.
158.
Difference between formal argument and actual argument?
Formal arguments are the arguments available in the function definition. They are preceded by their own data type. Actual arguments are available in the function call. These arguments are given as constants or variables or expressions to pass the values to the function.
Formal arguments are the arguments available in the function definition. They are preceded by their own data type. Actual arguments are available in the function call. These arguments are given as constants or variables or expressions to pass the values to the function.
159.
what are C tokens?
There
are six classes of tokens: identifier, keywords, constants, string literals,
operators and other separators.
160.
What are C identifiers?
These
are names given to various programming element such as variables, function,
arrays.It is a combination of letter, digit and underscore.It should begin with
letter. Backspace is not allowed.
161.
Difference between syntax vs logical error?
Syntax
Error
These involves validation of syntax of language.
compiler prints diagnostic message.
These involves validation of syntax of language.
compiler prints diagnostic message.
Logical
Error
logical error are caused by an incorrect algorithm or by a statement mistyped in such a way that it doesn’t violet syntax of language.
difficult to find.
logical error are caused by an incorrect algorithm or by a statement mistyped in such a way that it doesn’t violet syntax of language.
difficult to find.
162.
What are the facilities provided by preprocessor?
file inclusion
substitution facility/macro define
conditional compilation
file inclusion
substitution facility/macro define
conditional compilation
163.What
do the functions atoi(), itoa() and gcvt() do?
atoi()
is a macro that converts integer to character.
itoa() It converts an integer to string
gcvt() It converts a floating point number to string
itoa() It converts an integer to string
gcvt() It converts a floating point number to string
164.
What is FILE?
FILE
is a predefined data type. It is defined in stdio.h file.
165.
What is a file?
A
file is a region of storage in hard disks or in auxiliary storage devices.It
contains bytes of information .It is not a data type.
166.
What does static variable mean?
There
are 3 main uses for the static.
1.
If you declare within a function: It retains the value between function calls
2.
If it is declared for a function name: By default function is extern..so it
will be visible from other files if the function declaration is as static..it
is invisible for the outer files
3.
Static for global variables: By default we can use the global variables from
outside files If it is static global..that variable is limited to with in the
file.
167.
What are the different storage classes in C?
C
has three types of storage: automatic, static and allocated. Variable
having block scope and without static specifier have automatic storage
duration.
Variables
with block scope, and with static specifier have static scope. Global variables
(i.e, file scope) with or without the the static specifier also have static
scope. Memory obtained from calls to malloc(), alloc() or realloc()
belongs to allocated storage class.
168.
What is hashing?
To
hash means to grind up, and that’s essentially what hashing is all about. The
heart of a hashing algorithm is a hash function that takes your nice, neat data
and grinds it into some random-looking integer.
The
idea behind hashing is that some data either has no inherent ordering (such as
images) or is expensive to compare (such as images). If the data has no
inherent ordering, you can’t perform comparison searches.
169.
Can static variables be declared in a header file?
You
can’t declare a static variable without defining it as well (this is because
the storage class modifiers static and extern are mutually exclusive). A static
variable can be defined in a header file, but this would cause each source file
that included the header file to have its own private copy of the variable,
which is probably not what was intended.
170.
Can include files be nested?
Yes.
Include files can be nested any number of times. As long as you use
precautionary measures, you can avoid including the same file twice. In the
past, nesting header files was seen as bad programming practice, because it
complicates the dependency tracking function of the MAKE program and thus slows
down compilation. Many of today’s popular compilers make up for this difficulty
by implementing a concept called precompiled headers, in which all headers and
associated dependencies are stored in a precompiled state.
171.
What is a null pointer?
There
are times when it’s necessary to have a pointer that doesn’t point to anything.
The macro NULL, defined in , has a value that’s guaranteed to be different from
any valid pointer. NULL is a literal zero, possibly cast to void* or char*.
Some
people, notably C++ programmers, prefer to use 0 rather than NULL.
The null pointer is used in three ways:
1) To stop indirection in a recursive data structure.
2) As an error value.
3) As a sentinel value.
The null pointer is used in three ways:
1) To stop indirection in a recursive data structure.
2) As an error value.
3) As a sentinel value.
172.
How to reduce a final size of executable?
Size
of the final executable can be reduced using dynamic linking for libraries.
173.
Can you tell me how to check whether a linked list is circular?
Create
two pointers, and set both to the start of the list. Update each as follows:
while
(pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next;
if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular");
}
}
pointer1 = pointer1->next;
pointer2 = pointer2->next;
if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular");
}
}
If
a list is circular, at some point pointer2 will wrap around and be either at
the item just before pointer1, or the item before that. Either way, its either
1 or 2 jumps until they meet.
174.
Which bit wise operator is suitable for checking whether a
particular bit is on or off?
The
bitwise AND operator. Here is an example:
enum
{
KBit0 = 1,
KBit1,
…
KBit31,
};
if ( some_int & KBit24 )
printf ( “Bit number 24 is ON\n” );
else
printf ( “Bit number 24 is OFF\n” );
KBit0 = 1,
KBit1,
…
KBit31,
};
if ( some_int & KBit24 )
printf ( “Bit number 24 is ON\n” );
else
printf ( “Bit number 24 is OFF\n” );
175.
Which bit wise operator is suitable for turning off a particular
bit in a number?
The
bitwise AND operator, again. In the following code snippet, the bit number 24
is reset to zero.
some_int
= some_int & ~KBit24;
176.
What is the result of using Option Explicit?
When
writing your C program, you can include files in two ways. The first way
is to surround the file you want to include with the angled brackets < and
>. This method of inclusion tells the preprocessor to look for the file
in the predefined default location. This predefined default location is
often an INCLUDE environment variable that denotes the path to your include
files.
For
instance, given the INCLUDE variable
INCLUDE=C:\COMPILER\INCLUDE;S:\SOURCE\HEADERS; using the #include version of file inclusion, the compiler first checks the C:\COMPILER\INCLUDE directory for the specified file. If the file is not found there, the compiler then checks the S:\SOURCE\HEADERS directory. If the file is still not found, the preprocessor checks the current directory.
INCLUDE=C:\COMPILER\INCLUDE;S:\SOURCE\HEADERS; using the #include version of file inclusion, the compiler first checks the C:\COMPILER\INCLUDE directory for the specified file. If the file is not found there, the compiler then checks the S:\SOURCE\HEADERS directory. If the file is still not found, the preprocessor checks the current directory.
The
second way to include files is to surround the file you want to include with
double quotation marks. This method of inclusion tells the preprocessor to look
for the file in the current directory first, then look for it in the predefined
locations you have set up. Using the #include file version of file inclusion
and applying it to the preceding example, the preprocessor first checks the current
directory for the specified file. If the file is not found in the current
directory, the C:COMPILERINCLUDE directory is searched. If the file is still
not found, the preprocessor checks the S:SOURCEHEADERS directory.
The
#include method of file inclusion is often used to include standard headers
such as stdio.h or stdlib.h.
The
#include file include nonstandard header files that you have created for use in
your program. This is because these headers are often modified in the current
directory, and you will want the preprocessor to use your newly modified
version of the header rather than the older, unmodified version.
Comments
Post a Comment