Pages

Thursday, May 10, 2012

C FAQ

Any
company or any consultancy Need the Experienced or Fresher IT
professional Resume please send the mail to us from your official mail
id to this mail id softwarewalkins@gmail.com

FREE
Resume posting for the Job Seekers in this site, (This site is
JobSeekers Social networking of resumes of you and your Frineds ) you
can send your resume from all over the world with
experience and qualification dont send the projects and personal
details please write the heading ex: 3+ years of expe in IT to this mail
id softwarewalkins@gmail.com. it is like naukri and monster

It
is open database of the resumes if you have any objections dont send
your resume. send the resumes from all over the world Advantage of
this site is you can copy the your Resume link in the address bar and
paste in your compose mail so u need not to upload the resume when u r
applying for any post

FREE Job Requirement posting on www.allwalkin.blogspot.com. Please forward to softwarewalkins@gmail.com Do you have any material in any Technology in IT please send the soft copy to this mail id softwarewalkins@gmail.com

Any Govt jobs Material please send to us we will post in this site mail id softwarewalkins@gmail.comAccounts / Finance Jobs

A) switch statement is generally best to use when you have more than two
conditional expressions based on a single variable of numeric type.

2 What is the difference between goto and longjmp() and setjmp()?

A) goto statement implements a local jump of program execution, and the
longjmp() and setjmp() functions implement a nonlocal, or far, jump of
program
execution. General...

3 What is an lvalue?

A) An lvalue is an expression to which a value can be assigned. The lvalue
expression is located on the left side of an assignment statement,
whereas an
rvalue is located on the ...

4 Array is an lvalue or not?
A) An lvalue was defined as an
expression to which a value can be
assigned. Is
an array an expression to which we can assign a value? The answer to this
question is no, because an array...

5 What is page thrashing?
A) Some operating systems (such as UNIX or Windows in enhanced mode)
use virtual
memory. Virtual memory is a technique for making a machine behave as
if it had
more memory ...

6 What is a const pointer?

A)The access modifier keyword const is a promise the programmer makes
to the
compiler that the value of a variable will not be changed after it is
initialized. The compiler will enforc...

7 When should the register modifier be used? Does it really help?

A) The register modifier hints to the compiler
that the variable will be
heavily used and should be kept in the CPU's registers, if possible,
so that it
can be accessed faster. There ar...

8 when should the volatile modifier be used?
A) The volatile modifier is a directive to the compiler's optimizer that
operations involving this variable should not be optimized in certain
ways.
There are two special cases in which...

9 Can a variable be both const and volatile?
A) Yes. The const modifier means that this code cannot change the
value of the
variable, but that does not mean that the value cannot be changed by means
outside this code. For instance...

10 How reliable are floating-point comparisons?
A) Floating-point numbers are the "black art" of computer
programming. One
reason why this is so is that there is no optimal way to represent an
arbitrary
number. The Institute of Elect...

11 How can you determine the maximum value that a numeric variable can
hold?
A) For integral types, on a machine that uses two's complement arithmetic
(which is just about any machine you're likely to use), a signed type
can hold
numbers from –2(number of bits –...

12 When should a type cast be used?
A) There are two situations in which to use a type cast. The first use
is to
change the type of an operand to an arithmetic operation so that the
operation
will be performed properly.&n...

13 When should a type cast not be
used?
A) A type cast should not be used to override a const or volatile
declaration.
Overriding these type modifiers can cause the program to fail to run
correctly.

14 Is it acceptable to declare/define a variable in a C header?
A) global variable that must be accessed from more than one file can
and should
be declared in a header file. In addition, such a variable must be
defined in
one source file. Variable...

15 What is the difference between declaring a variable and defining a
variable?
A) Declaring a variable means describing its type to the compiler but not
allocating any space for it. Defining a variable means declaring it
and also
allocating space to hold the
variable

16 Can static variables be declared in a header file?
A) 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...

17 What is the benefit of using const for declaring constants?
The benefit of using the const keyword is that the compiler might be
able to
make optimizations based on the knowledge that the value of the
variable will
not change. In addition, th...

18 What is the easiest sorting method to use?
The answer is the standard library function qsort(). It's the easiest
sort by
far for several reasons:
It is already written.
It is already
debugged.
...

19 What is the quickest sorting method to use?
The answer depends on what you mean by quickest. For most sorting
problems, it
just doesn't matter how quick the sort is because it is done
infrequently or
other operations take sign...

20 How can I sort things that are too large to bring into memory?
A sorting program that sorts items that are on secondary storage (disk or
tape) rather than primary storage (memory) is called an external sort.
Exactly
how to sort large data...
21 What is the easiest searching method to use?
Just as qsort() was the easiest sorting method, because it is part of the
standard library, bsearch() is the
easiest searching method to use. If the given array is
in th...

22 What is the quickest searching method to use?
A binary search, such as bsearch() performs, is much faster than a linear
search. A hashing algorithm can provide even faster searching. One
particularly
interesting and fast method ...

23 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 so...

24 How can I sort a linked list?
Both the merge sort and the radix sort are good sorting algorithms to
use for
linked lists.

25 How can I search for data in a linked list?
Unfortunately, the only way to search a linked list is
with a linear
search,
because the only way a linked list's members can be accessed is
sequentially.
Sometimes it is quicker to ...

26 How do you redirect a standard stream?
Most operating systems, including DOS, provide a means to redirect program
input and output to and from different devices. This means that rather
than your
program output (stdout) go...

27 How can you restore a redirected standard stream?
The preceding example showed how you can redirect a standard stream from
within your program. But what if later in your program you wanted to
restore the
standard stream to its or...

28 What is the difference between text and binary modes?
Streams can be classified into two types: text
streams and binary streams.
Text streams are interpreted, with a maximum length of 255 characters.
With text
streams, car...

29 How do you determine whether to use a stream function or a low-level
function?
Stream functions such as fread() and fwrite() are buffered and are more
efficient when reading and writing text or binary data to files. You
generally
gain better performance by usin...

30 How can I open a file so that other programs can update it at the same
time?
Your C compiler library contains a low-level file function called
sopen() that
can be used to open a file in shared mode. Beginning with DOS 3.0,
files could
be opened in shar...

31 How can I make sure that my
program is the only one accessing a file?
By using the sopen() function you can open a file in shared mode and
explicitly deny reading and writing permissions to any other program
but yours.
This task is accomplished by usin...

32 What is Preprocessor?
The preprocessor is used to modify your program according to the
preprocessor
directives in your source code. Preprocessor directives (such as
#define) give
the preprocessor s...

33 What is a macro, and how do you use it?
A macro is a preprocessor directive that provides a mechanism for token
replacement in your source code. Macros are created by using the #define
statement.
Here is...

34 What will the preprocessor do for a
program?
The C preprocessor is used to modify your program according to the
preprocessor directives in your source code. A preprocessor directive is a
statement (such as #define) that ...

35 How can you avoid including a header more than once?
One easy technique to avoid multiple inclusions of the same header is
to use
the #ifndef and #define
preprocessor directives. When you create a header for your program, ...

36 Can a file other than a .h file be included with #include?
The preprocessor will include whatever file you specify in your #include
statement. Therefore, if you have the line
#include <macros.inc>
in you...

37 What is the benefit of using #define to declare a constant?
Using the #define
method of declaring a constant enables you to declare a
constant in one place and use it throughout your program. This helps
make your
programs more maintainable, b...

38 What is the benefit of using an enum rather than a #define constant?
The use of an enumeration constant (enum) has many advantages over
using the
traditional symbolic constant
style of #define. These advantages include a low...

39 How are portions of a program disabled in demo versions?
If you are distributing a demo version of your program, the
preprocessor can
be used to enable or disable
portions of your program. The following portion of code shows h...

40 Is it better to use a macro or a function?
The answer depends on the situation
you are writing code for. Macros
have the
distinct advantage of being more efficient (and faster) than
functions, because
their corresponding code...

41 What is the difference between #include <file> and #include "file"?
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 me...

42 Can you define which header file to include at compile time?
Yes. This can be done by using the #if, #else, and #endif preprocessor
directives. For example, certain
compilers use different names for header files. One such case is ...

43 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 s...

44 How many levels deep can include files be nested?
Even though there is no limit to the number of levels of nested
include files
you can have, your compiler might
run out of stack space while trying to include an inordinately high nu...

45 How can type-insensitive macros be created?
A type-insensitive macro is a macro that performs the same basic
operation on
different data types. This task can be accomplished by using the
concatenation
operator to create a call...

46 What are the standard predefined macros?
The ANSI C standard defines six predefined
macros for use in the C
language:
Macro Name Purpose
_ _LINE_ _ Inserts the current source code line numbe...

47 What is a pragma?
The #pragma preprocessor directive allows each compiler to implement
compiler-specific features that can
be turned on and off with the #pragma statement. For instance, y...

48 What is #line used for?
The #line preprocessor directive is used to reset the values of the _
_LINE_ _
and _ _FILE_ _ symbols,
respectively. This directive is commonly used in fourth-generation...

49 How do you override a defined macro?
You can use the #undef preprocessor directive to undefine (override) a
previously defined macro.

50 How can you check to see
whether a symbol is defined?
You can use the #ifdef and #ifndef preprocessor directives to check
whether a
symbol has been defined
(#ifdef) or whether it has not been defined (#ifndef).
51 What is the difference between a string copy (strcpy) and a memory copy
(memcpy)? When should each be used?
The strcpy() function is designed to work exclusively with strings. It
copies
each byte of the source string to the destination string and stops
when the
terminating null characte...

52 How can I convert a number to a string?
The standard C library provides several functions for converting
numbers of
all formats (integers, longs, floats, and so on) to strings and vice versa

53 How can I convert a string
to a number?
The standard C library provides several functions for converting
strings to
numbers of all formats (integers, longs, floats, and so on) and vice
versa.

54 How do you print only part of a string?
/* Use printf() to print the first 11 characters of source_str. */
printf("First 11 characters: `%11.11s'n", source_str);

55 What is indirection?
If you declare a variable, its name is a direct reference to its
value. If you
have a pointer to a variable, or any other object in memory, you have an
indirect reference to its valu...

56 How many levels of pointers can you have?
The answer depends on what you mean by "levels of pointers." If you
mean "How
many levels of
indirection
can you have in a single declaration?" the answer is "At least 1...

57 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 <stddef.h>, has a value that's
guaranteed
to be different from ...

58 What is a void pointer?
A void pointer is a C convention for "a raw address." The compiler has
no idea
what type of object a void
Pointer "really points to." If you write
int *ip; ...

59 Is NULL always defined as 0?
NULL is defined as either 0 or (void*)0. These values are almost
identical;
either a literal zero or a void pointer
is converted
automatically to any kind of pointer, as...

60 What does it mean when a pointer is used in an if statement?
Any time a pointer is used as a condition, it means "Is this a non-null
pointer?" A pointer can be used in an
if, while, for, or do/while statement, or in a conditional ...

61 Can you add pointers together? Why would you?
No, you can't add pointers together. If you live at 1332 Lakeview
Drive, and
your neighbor lives at 1364
Lakeview, what's 1332+1364? It's a number, but it doesn't mean a...

62 How do you use a pointer to a function?
The hardest part about using a pointer-to-function is declaring it.
Consider an example. You want to create a pointer, pf, that points to the
strcmp() function.

63 When would you
use a pointer to a function?
Pointers to functions are interesting when you pass them to other
functions. A
function that takes function pointers says, in effect, "Part of what I
do can be
customized. Give me a ...

64 Why should we assign NULL to the elements (pointer) after freeing them?
This is paranoia based on long experience. After a pointer has been
freed, you
can no longer use the pointed-to data. The pointer is said to "dangle"; it
doesn't point at anything us...

65 Is it better to use malloc() or calloc()?
Both the malloc() and the calloc() functions are used to allocate dynamic
memory. Each operates slightly different from the other. malloc()
takes a size
and returns a pointer to a
ch...

66 What is the difference between far and near?
As described at the beginning of this chapter, some compilers for PC
compatibles use two types of pointers.
near pointers are 16 bits long and can address a 64KB range. ...

67 When should a far pointer be used?
Sometimes you can get away with using a small memory model in most of
a given
program. There might be just a few things that don't fit in your small
data and
code segments. When that...

68 What is the stack?
The stack is where all the functions' local (auto) variables are
created. The
stack also contains some
information used to call and return from functions.
A...

69 Can the size of an array be declared at
runtime?
No. In an array declaration, the size must be known at compile time.
You can't
specify a size that's known
only at runtime. For example, if i is a variable, you can't wr...

70 What is the heap?
The heap is where malloc(), calloc(), and realloc() get memory.
Getting memory from the heap is much slower than getting it from the
stack. On
the other hand, the heap <...

71 What is the difference between NULL and NUL?
NULL is a macro defined in <stddef.h> for the null pointer.
NUL is the name of the first character in the ASCII character set. It
corresponds to a zero value. Ther...

72 What is a "null pointer assignment" error? What are bus errors, memory
faults, and core
dumps?
These are all serious errors, symptoms of a wild pointer or subscript.
Null pointer assignment is a message you might get when an MS-DOS program
finishes executing. Some...

73 How can you determine the size of an allocated portion of memory?
You can't, really. free() can , but there's no way for your program to
know
the trick free() uses. Even if you disassemble the library and
discover the
trick, there's no guarantee th...

74 Can math operations be performed on a void pointer?
No. Pointer addition and subtraction are based on advancing the
pointer by a
number of elements. By definition, if you have a void pointer, you
don't know
what it's pointing to, so y...

75 How do you print an
address?
The safest way is to use printf() (or fprintf() or sprintf()) with the %P
specification. That prints a void
pointer (void*). Different compilers might print a pointer wi...

76 Why should I prototype a function?
A function prototype tells the compiler what kind of arguments a
function is
looking to receive and what
kind of return value a function is going to give back. This appr...

77 What is a static function?
A static function is a function whose scope is limited to the current
source
file. Scope refers to the visibility
of a function or variable. If the functio...

78 Is it possible to execute code even after the program exits the main()
function?
The standard C library provides a
function named atexit() that can be
used to
perform "cleanup" operations when your program terminates. You can set
up a set
of functions you want to...

79 Is using exit() the same as using return?
No. The exit() function is used to exit your program and return
control to the
operating system. The return
statement is used to return from a function and return contro...

80 Can the sizeof operator be used to tell the size of an array passed
to a
function?
No. There's no way to tell, at runtime, how many elements are in an array
parameter just by looking at the
array parameter itself. Remember, passing an array to a functi...
81 Is it better to use a pointer to navigate an array of values,or
is
it better
to use a subscripted array name?
It's easier for a C compiler to generate good code for pointers than for
subscripts.

82 What is the difference between a string and an array?
An array is an array of anything. A string is a specific kind of an
array with
a well-known convention to
determine its length.
There are two kinds of progr...

83 what is a modulus operator? What are the restrictions of a modulus
operator?
A Modulus operator gives the remainder value. The result of x%y is
obtained by
(x-(x/y)*y). This operator is applied only to integral operands and
cannot be
applied to float o...

84 why n++ executes faster than n+1?
The
expression n++ requires a single machine instruction such as INR
to carry
out the increment operation whereas, n+1 requires more instructions to
carry out
this operation.

85 Write the equivalent expression for x%8?
x&7

Write expressions to swap two integers without using a temporary variable?

87 What is storage class and what are storage variable ?
A storage class is an attribute that changes the behavior of a
variable. It
controls the lifetime, scope and linkage.
There are five types of storage classes
1)au...

88 What
are the advantages of auto variables?
1)The same auto variable name can be used in different blocks
2)There is no side effect by changing the values in the blocks
3)The memory is economically used

89 Diffenentiate between an internal static and external static variable?
An internal static variable is declared inside a block with static storage
class whereas an external static variable is declared outside all the
blocks in
a file.An internal static variable has persis...

90 What are advantages and disadvantages of external storage class?
Advantages of external storage class
1)Persistent storage of a variable retains the latest value
2)The value is globally available

A linker converts an object code into an executable code by linking
together
the necessary build in functions. The form and place of declaration
where the
variable is declared in a program determine ...

93 What are the characteristics of arrays in C?

1) An array holds elements that have the same data type
2) Array elements are stored in subsequent memory locations
3) Two-dim...

94 When does the compiler not implicitly generate the address of the first
element of an array?
Whenever an array name appears in an expression such as
Ø array as an operand of the sizeof operator
Ø
array as an ...

95
What is 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 mo...

96 What is a function and built-in 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 a
large program.such subprograms are functions.
...

97 What is an argument ? differentiate between formal arguments and actual
arguments?

An argument is an entity used to pass the data from calling funtion to the
called funtion. Formal
arguments are the arguments available in the
funtion
definition.They are preceded by their own data t...

98 What is the purpose of main( ) function?
The function main( ) invokes other functions within it.It is the first
function to be called when the program starts execution.
Ø It is the starting function...

99 What are the advantages of the functions?

Ø Debugging is easier
Ø It is easier to understand the logic involved in the program
Ø ...

100 what is a method?
a way of doing something, especially a systematic way; implies an orderly
logical arrangement (usually in steps)
101 What is a pointer value and address?

A pointer value is a data object that refers to a memory
location.
Each memory locaion is numbered in the memory.The number attached to a
&...

102 What is a pointer variable?
A pointer variable is a variable that may contain the address of another
variable or any valid address in the memory.

103 Are pointers integers?
No, pointers are not integers.A pointer is an address.It is merely a
positive number and not an integer.

104 How are pointer variables initialized?

Pointer variable are initialized by one of the following two ways
Ø Static memory all...

105 What is static memory allocation and dynamic memory allocation?

Static memory allocation: The compiler allocates the required memory space
for a declared variable.By using the address of operator,the
reserved
address is
obtained and ...

106 What is the purpose of realloc( )?
the function realloc(ptr,n) uses two arguments.the first argument ptr is a
pointer to a block of memory for which the size is to be altered.The
second
argument n specifies the new size.The size may b...

107 Diffence arrays and pointers?
Ø Pointers are used to manipulate data using the address. Pointers use *
operator to access the data pointed to by them
Ø ...