Professional Documents
Culture Documents
What Is A Source File?: (Supraja-S2)
What Is A Source File?: (Supraja-S2)
A source file is a collection of set of instructions designed to perform a particular task. Source
file is primarily used as input to the Translator that produces an executable file (i.e., it is
compiled or interpreted).
[ Supraja-S2]
A header file is a collection of function declarations. A header file can also contain constants,
global variables, macro's that needs to be shared by many functions. A source file can make use
of the header file by including it.
[Ramya-s2]
[Nilesh-s2]
[Priya-S2]
[Girish-s2]
The compiler uses the information in a function prototype for type checking.
[vivek-S2]
> The first argument is of the type integer,it is usually referred as argc as it keep the argument
count. It contains the number of arguments passed to the program from the command line,
including the name of the program.
>The second argument is an array of character pointers. It contains all the command-line
arguments. It is usually referred as argv. argv[0] holds the name of the program. Argv[1] holds
the second command line argument (if any) and so on.
[sneha,s2]
[Santosh-S2]
#include is a pre-processor directive. It includes the file named stdio.h which is header file into the
current source file. The angle brackets specifies the pre-processor to search the file in standard
directory .
18.What does #include “stdio.h” mean?
#include is a pre-processor directive. It includes the file named stdio.h which is header file into the
current source file. The “ ” (double quotes) specifies the pre-processor to start the search
from the current directory . If the file is not present in the current directory then search
continues with standard directory
3. Linker: input is .obj file links the standard library files into the assembly file. After successful
linking process executable file is created (a.out)
[Dileep Raj-S2]
And converts it into low level language ,it also checks for syntax and schematic errors
, it converts source file into an executable file if no errors present , if present if will display errors
[Rudrappa-s2]
STACK
HEAP
DATA
SEGMENT
TEXT
SEGMENT
Typical logical memory layout of a process
Process Layout:
➢ Stack: All automatic variables are stored into stack area. It follow LIFO data-
structure. Stack is used for temporary storage of data.
➢ Heap: The heap area is used for dynamic memory allocations. It is managed by
the programmer using memory management functions.
[Priyanka, Sneha-s2]
[Sushmita Mazumdar-S2]
26. What is heap?
The heap is the section of computer memory (memory segment) where all the variables
created or initialized at runtime are stored.
The heap is extremely important because it is available for use by applications during
execution using the C functions malloc (memory allocate) and free. The heap allows
programmers to allocate memory when needed and free it when not required. Thus it is the
programmer’s responsibility to manage heap.
[Ramya-S2]
[Siva-S2]
1. Automatic
2. Static
Several keywords, together with the context of an object’s declaration, specify its storage class.
[Priya-S2]
The storage class defines the lifetime of an object i.e. It decides when the variable comes
into existence and when it gets destroyed.
[Priya-S2]
● auto
● static
● register
● extern and
● typedef.
[Ramya-S2]
[Santosh-S2]
40.What is a macro?
Macro is a #defined constant, which when used in the code, the preprocessor will
replace the macro with its replacement text. It is a convention that all macros or #defined constants are
in uppercase.
[Mujeeb-S2]
__FILE__
__LINE__
__DATE__
__TIME__
__STDC__
#include <assert.h>
main()
{
int x;
printf("\nEnter an integer value: ");
scanf("%d", &x);
assert(x >= 0);
printf("You entered %d.\n", x);
return(0);
}
Enter an integer value: -1
Assertion failed: x, file vivek.c, line 7
Abnormal program termination.
int i=5;
now ++i++;
[VIVEK, S2]
a = 10;
In GCC compiler error can be like this “Increment of read –only variable a”.
[Sushmita Mazumdar-S2]
[Nandini.S-S2]
➢ Syntax Errors: Error due to missing colon, semicolon, parenthesis, etc. Syntax is the
way in which we construct sentences by following principles and rules.
➢ Divide by Zero
'5=x' (or '5=3') is not legal because ‘5’ is constant and has no address.
[ Priyanka-S2 ]
[Sneha – S2]
51. List the various reasons for segmentation fault?
-A buffer overflow
[Rashmita,S2]
52.Explain typecasting?
Typecasting is a way to make a variable of one type to another using typecast operator.
Eg: void *ptr;
int i=10;
ptr=&i;
printf(“%d”,*(int*)ptr);
[Priya-S2]
● Explicit typecasting.
[Supraja-S2]
[Ramya-S2]
59. Give the difference b/w constant pointer and pointer to a constant?
Explain with an example.
In case of constant pointer the pointer cannot be reinitialized, where as in pointer to a constant the object
to which the pointer is pointing to is constant.
Ex: constant pointer
int *const p;
the const keyword should be between star(*) and the pointer name.
Pointer to a constant
const int* p;
The const keyword can be either before or after data type.
● malloc ().
● calloc ().
● realloc ().
● free ().
Command line arguments are passed when executing a program. Command-line arguments are
given at the prompt separated by space. Command line input is treated as a string.
62. How do you write a function to take variable number of arguments? List
its restrictions?
Return type function name (known type, ...)
It can have any number of known types of arguments and eclipse (…) will be the last
argument in variable length argument list.
Restriction: In the argument list there should be at-least one known argument.
… should be the last argument if the function takes many aguments
[Amar-S2]
[ajay-s2]
66. What does printf() return?
Ans: Return type of printf function is an integer . On success it return’s the no of character printed
on the o/p screen. On failure it will return -1.
[ajay-s2]
The stdio.h is having declarations of standard library I/O functions , some standard
macros and structure templates .
Eg: printf(),scanf(),NULL,FILE.
[ajay-s2]
[ajay-s2]
[ajay-s2]
[Nandini.s s2]
[Sneha-S2]
Two’s complement is obtained by first finding the 1's complement and then adding
1 to the 1's complement .
1111 will be a negative number coz the MSB is used to know whether the number is
actually negative or a positive. If the MSB is 1 it's treated as negative and if 0 it's
treated as positive.
[ Priyanka – S2 ]
• The following figure shows the layout for single (32-bit) precision
floating-point values. The number of bits for each field are shown
(bit ranges are in square brackets):
sign exponent fraction bias
Single precision 1[31] 8[30-23] 23[22-00] 127
• The exponent
• The exponent field needs to represent both positive and negative
exponents.
• To do this, a bias is added to the actual exponent in order to get
the stored exponent.
• For IEEE single-precision floats, this value is 127.
Thus, an exponent of zero means that 127 is stored in the exponent
field.
Exponents of -127 (all 0s) and +128 (all 1s) are reserved for special
numbers
• The mantissa
• The mantissa, also known as the significant, represents the
precision bits of the number. It is composed of an implicit leading
bit and the fraction bits.
• The mantissa is composed of the fraction and an implicit leading
digit .The exponent base (2) is implicit and need not be stored.
• To find out the value of the implicit leading bit, consider that any
number can be expressed in scientific notation in many different
ways.
For example, the number five can be represented as any of these:
5.00 × 100
0.05 × 102
5000 × 10-3
• Normalized form
5.00 × 100
0.05 × 102
5000 × 10-3
• In order to maximize the quantity of representable numbers, floating-
point numbers are typically stored in normalized form.
• This basically puts the radix point after the first non-zero digit.
• In normalized form, five is represented as
5.0 × 100.
• In base two, since the only possible non-zero digit is 1. We can
just assume a leading digit of 1, and don't need to represent it
explicitly.
• As a result, the mantissa has effectively 24 bits of resolution, by
way of 23 fraction bits.
• Special values
• Not A Number: The value NaN is used to represent a value that does
not represent a real number.
• NaN's are represented by a bit pattern with an exponent of all 1s
and a non-zero fraction.
• There are two categories of NaN:
QNaN (Quiet NaN) and
SNaN (SignallingNaN).
• Special values
[Nandini.s s2]
Constant: A constant value is the one which does not change during the execution of a
program.
[Supraja-S2]
77.what is size_t? List any two library function which make use of
it?
Size_t is an unsigned integer type.
[Rashmita-S2]
[Siva-S2]
[Amar-S2]
[ajay-s2]
● union allocates the memory equal to the maximum memory required by the
member of the union but structure allocates the memory equal to the total
memory required by the members.
● In union, memory is shared by all the members of union but in case of structure
each member have their own memory space.
[Sneha – S2]
89. What is structure padding (alignment)?
Size of the structure is compiler dependent because in some implementations extra bytes are
added in the structure, these extra bytes are called as padding. So that memory is aligned and
every object appears at even address location.
● Internal padding: In this the padding is done between the elements of structures.
● External padding: In this padding is done at the end of structure.
char variable are byte aligned and can appear at any byte boundary.
Short variables are 2 byte & can appear at multiple of 2 byte boundary.
Long variable are 4 byte so they should appear at the multiple of 4 byte boundary.
Struct example {
char c1;
short s1;
char c2;
long l1;
char c3;
}; external padding
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
C1 Padd S1 S1 C2 Padd Padd Padd L1 L1 L1 L1 C3 Padd Padd Padd
ing ing ing ing ing ing ing
[Sushmita Mazumdar-S2]
[Priyanka-S2]
[Sneha- S2]
In a little-endian system the least significant value in the sequence is stored first.(lowest storage
address)
[Rashmita-s2]
In a big-endian system the most significant value in the sequence is stored at the lowest storage
address.
[Rashmita-s2]
[Shuvashanmugam-S2]
-The continue statement can be used to skip the rest of the body of an iterative loop. The use of a
continue statement violates the rules of structured programming, however, and a section
of code which uses a continue statement can always be rewritten to omit the continue.
- The continue statement can only be used within the body of a while, do, or for statement.
-They are identicdal in terms of speed and memory consumption. You can always substitute a
while loop for a for loop, but not the other way around.For the syntax the two loops are
the same.
-The main difference comes into picture when you use continue with them i.e. for and while.
In a while loop if continue is used before the increment of a variable is done it converts
into a infinite loop.
i=1;
while(i<10)
{
/* do stuff */
if(i==6);
continue;
i++;
}
The above piece of code will turn into an infinite loop.
for(i=1;i<10;i++)
{
/* do stuff */
if(i==6);
continue;
}
In the above for loop the value of will be incremented once it attains the value 6.
Therefore it will not turn into a infinite loop.
99.What is a stack frame . Explain what might get saved to stack frame ?
-A stack frame is a memory management strategy used to create and
destroy temporary (automatic) variables in some programming languages. Among
other things, use of a stack allows programming languages to allow recursive calling of
functions. Stack frames only exist at run-time
- Each stack frame contains space for actual parameters, local variables, temporary
locations, and (in some architectures) information about the calling context such as the
memory address of the calling function. When the called function finishes executing,
its stack frame is removed from the stack, and execution resumes back in the calling
function.
-The goto statement is discouraged in C, because it alters the sequential flow of logic
that is the characteristic of C language. This word is redundant in C and encourages
poor programming style.
- The global variable has a global scope and life time of the whole program. The
memory is allocated for each and every object.
-while a static variable has a local scope(can't be used outside the scope) but life time
of the whole program( its value persists even if the function returns). The memory is
allocated for static variables only once i.e all the objects shared by same memory
compound-statement :
{ declaration-list opt statement-list opt }
Where:
declaration-list :
declaration
declaration-list declaration
statement-list :
statement
statement-list statement
[Girish-S2]
float f= 1.10;
i= f;
printf(“%d”,i);
value of i is 1.
[Sushmita Mazumdar-S2]
[ Priyanka-S2 ]
Ex:
struct {
int i;
int b;
char c;
[Nandini.s s2]
[Sneha – s2]
These are the statements which yields ambiguity in answers in different platform and there is
confusion in the evaluation of expression.
Eg: a[i]=i++;
[Sneha – s2]
[Shuvashanmugam-S2]
[Nandini.s-S2]
[Sushmita Mazumdar-S2]
[Priyanka-S2]
[Sneha – S2]
124. Summaries the differences in array declaration as per C89 and C99
std ?
In C89 std we declare the size of array at the time of decleration of array.
C99 adds a new array type called a variable length array type.
The *static *storage class specifier and any of the type-qualifiers, *
restrict*, *const *or *volatile*, can appear inside the *[ *and *] *that are
used to declare an array type, but only in the outermost array type
derivation of a function parameter.
[Vivek-S2]
[Girish-S2]
Ans. Each call of a recursive algorithm either solves one part of the problem or it reduces the
size of the problem.
The general part of the solution is the recursive call. At each recursive call, the size of the
problem is reduced.
The case when the function does not call itself recursively. This is called a base case.
We can also say that the statement that “solves” the problem is known as the base case.
Every function must have a base case; otherwise, the function will keep calling itself and will
never get around to returning a value.
The program will either crash or it will continue until an external effect stops it; it will certainly
not find the right value.
[Ankit Jain-S1]
Ans. If the recursive call occurs at the end of a method, it is called a tail recursion. The tail
recursion is similar to a loop. The method executes all the statements before jumping into the
next recursive call.
If the recursive call occurs at the beginning of a method, it is called a head recursion. The
method saves the state before jumping into the next recursive call. Compare these:
{ {
if(n == 1) if(n == 0)
return(1); return(1);
else else
printf("n=%d",n); head(n-1);
tail(n-1); printf("n=%d",n);
} }
Middle Recursion:The middle recursion has the recursive code in between other statements of
the function. In a function using middle recursion, there are statements, before as well as after
the recursive call.
if(n== 0)
return(1);
else
{
printf("n=%d",n);
middle(n-1);
printf("n=%d",n);
[Ankit Jain-S1]