Question based on C language..
1) What are the key
features of C programming language?
·
C is a
platform-dependent language.
·
C offers the
possibility to break down a large program into small modules.
·
Also, the
possibility of a programmer to control the language.
·
C comes with
support for system programming and hence it compiles and executes with high
speed when compared to other high-level languages.
2) What is the use of
header files in C?
Header files contain the definitions and set of rules
of the functions being used in the programs.
For example:-
when
you use printf() or scanf() in your program, you nee to include stdio.h library
function. Else your compiler will show an error. This is because, the standard
input and output functions printf() and scanf() are stored in this header file.
So similarly every header file stores a set of predefined
functions which makes it easy to program.
3) What happens if a
headerfile is included twice?
When the pre-processor sees a #include, it replaces the
#include with the contents of the specified header. By using include guard(#),
you can prevent a header file from being included multiple times during the
compilation process. So basically, if a header file with proper syntax is included
twice, the second one gets ignored.
4) Can a program be compiled
without the main() function?
Yes, compilation is possible, but the execution is not
possible. However, if you use #define, we can execute the program without the need of
main().
For Example:
#include<stdio.h> #define start main void begin() { printf("Hello World"); }
5) What is the difference
between static & global variables?
Global variables are
variables which are defined outside the function. The scope of global variables
begins at the point where they are defined and lasts till the end of the
file/program. Whereas, static global variables are private to the source file
where they are defined and do not conflict with other variables in other source
files which would have the same name.
6) What is Memory Leak in
C?
A memory leak occurs when programmers create a memory in the heap
and forget to delete it. It decreases the efficiency of
the performance of the system.
7) What is the difference
between while (0) and while (1)?
While(1) is an infinite
loop which will run till a break statement occurs.
Similarly, while(2), while(3), while(255) etc will all give infinite loops
only.
Whereas, While(0) does the exact opposite of this.
When while(0) is used, it means the conditions will always be false. Thus, as a
result, the program
will never get executed.
8) What is a Dangling
Pointer in C?
A pointer pointing to a de-referenced memory location
is called dangling pointer. i.e. pointer pointing to the memory location which is
deleted. There are three different ways where a pointer can act
as a dangling pointer.
·
De-allocation
of memory
·
When the
local variable is not static
·
When the
variable goes out of scope
9) What is the difference
between the Void and Null Pointer?
Null pointers generally do
not point to a valid location. A pointer is initialized as NULL if we
are not aware of its value at the time of declaration.
Whereas, Void pointers are general-purpose pointers
which do not have any type associated with them and can contain the address of
any type of variable. So basically, the type of data that it points to can be anything.
10) Difference between
malloc() and calloc() functions?
malloc and calloc are library functions that
allocate
memory dynamically, which means that memory is allocated during the runtime
from the heap segment.
Malloc and Calloc differ in the number of arguments used,
their initialization methods and also in the return values
11) What is the difference
between a structure and a Union?
·
All the
members of a structure can be accessed simultaneously but union can access only
one member at a time
·
Altering the
value of a member will not affect the other members of the structure but
where it affects the members of a union
·
Lesser
memory is needed for a union variable than a structure variable of the same
type
12) Write a program to
print “hello world” without using a semicolon?
#include <stdio.h> void main() { if(printf("Hello World")) { }}
Comments
Post a Comment