C Programming short QNA
C Programming short QNA
It’s a pointer variable which can hold the address of another pointer variable. It de-
refers twice to point to the data held by the designated pointer variable.
Both allocates memory from heap area/dynamic memory. By default calloc fills the
allocated memory with 0’s.
By default every local variable of the function is automatic (auto). In the below
function both the variables ‘i’ and ‘j’ are automatic variables.
void f() {
int i;
auto int j;
4. What are the valid places for the keyword break to appear?
Break can appear only with in the looping control and switch statement. The purpose
of the break is to bring the control out from the said blocks.
5. What is difference between including the header file with-in angular braces <
> and double quotes “ “
If a header file is included with in < > then the compiler searches for the particular
header file only with in the built in include path. If a header file is included with in “ “,
then the compiler searches for the particular header file first in the current working
directory, if not found then in the built in include path.
Get the two’s compliment of the same positive integer. Eg: 1011 (-5)
A static local variables retains its value between the function call and the default value
is 0. The following function will print 1 2 3 if called thrice.
void f() {
static int i;
++i;
printf(“%d “,i);
If a global variable is static then its visibility is limited to the same source code.
8. What is a NULL pointer?
A pointer initially holding valid address, but later the held address is released or freed.
Then such a pointer is called as dangling pointer.
11. What is the purpose of the keyword typedef?
It is used to alias the existing type. Also used to simplify the complex declaration of
the type.
The expression appearing on right side of the assignment operator is called as rvalue.
Rvalue is assigned to lvalue, which appears on left side of the assignment operator. The
lvalue should designate to a variable not a constant.
The parameters sent to the function at calling end are called as actual parameters while
at the receiving of the function definition called as formal parameters.
Yes, it can be but cannot be executed, as the execution requires main() function
definition.
When we do not know what type of the memory address the pointer variable is going
to hold, then we declare a void pointer for such.
17. What is the difference between variable declaration and variable definition?
Declaration associates type to the variable whereas definition gives the value to the
variable.
18. Does a built-in header file contains built-in function definition?
No, the header file only declares function. The definition is in library which is linked
by the linker.
Preprocessor is a directive to the compiler to perform certain things before the actual
compilation process begins.
The arguments which we pass to the main() function while executing the program are
called as command line arguments.
Opens a file both for reading and writing. If a file is not existing it creates one, else if
the file is existing it will be over written.
Error, It is invalid that either of the operands for the modulus operator (%) is a real
number.
30. How many operators are there under the category of ternary operators?
Dennis M Ritchie.
while(0 == 0) {
Local variables get garbage value and global variables get a value 0 by default.
38. How can we determine whether a file is successfully opened or not using
fopen() function?
int data type only capable of storing values between – 32768 to 32767.To store 32768
a modifier needs to use with int data type. Long Int can use and also if there is no any
negative values unsigned int is also possible to use.
• Short
• Long
• Signed
• Unsigned
• long long
A loop running within another loop is referred as a nested loop. The first loop is called
Outer loop and inside the loop is called Inner loop. Inner loop executes the number of
times define an outer loop.
++a is called prefixed increment and the increment will happen first on a variable. a++ is
called postfix increment and the increment happens after the value of a variable used for
the operations.
43. What is the difference between Call by Value and Call by Reference?
When using Call by Value, you are sending the value of a variable as parameter to a
function, whereas Call by Reference sends the address of the variable. Also, under Call
by Value, the value in the parameter is not affected by whatever operation that takes
place, while in the case of Call by Reference, values can be affected by the process
within the function.
Source codes are codes that were written by the programmer. It is made up of the
commands and other English-like keywords that are supposed to instruct the computer
what to do. However, computers would not be able to understand source codes.
Therefore, source codes are compiled using a compiler. The resulting outputs are object
codes.
45. Compare and contrast compilers from interpreters.
Compilers and interpreters often deal with how program codes are executed.
Interpreters execute program codes one line at a time, while compilers take the program
as a whole and convert it into object code, before executing it. The key difference here
is that in the case of interpreters, a program may encounter syntax errors in the middle
of execution, and will stop from there. On the other hand, compilers check the syntax
of the entire program and will only proceed to execution when no syntax errors are
found.
46. What are header files and what are its uses in C programming?
Header files are also known as library files. They contain two essential things: the
definitions and prototypes of functions being used in a program. Simply put, commands
that you use in C programming are actually functions that are defined from within each
header files. Each header file contains a set of functions. For example: stdio.h is a
header file that contains definition and prototypes of commands like printf and scanf.
Syntax errors are associated with mistakes in the use of a programming language. It
maybe a command that was misspelled or a command that must was entered in
lowercase mode but was instead entered with an upper case character. A misplaced
symbol, or lack of symbol, somewhere within a line of code can also lead to syntax
error.
48. What are variables and it what way is it different from constants?
Variables and constants may at first look similar in a sense that both are identifiers
made up of one character or more characters (letters, numbers and a few allowable
symbols). Both will also hold a particular value. Values held by a variable can be
altered throughout the program, and can be used in most operations and computations.
Constants are given values at one time only, placed at the beginning of a program. This
value is not altered in the program. For example, you can assigned a constant named PI
and give it a value 3.1415 . You can then use it as PI in the program, instead of having
to write 3.1415 each time you need it.
Preprocessor directives are placed at the beginning of every C program. This is where
library files are specified, which would depend on what functions are to be used in the
program. Another use of preprocessor directives is the declaration of constants.
Preprocessor directives begin with the # symbol.
The switch statement is best used when dealing with selections based on a single
variable or expression. However, switch statements can only evaluate integer and
character data types.
52. What are global variables and how do you declare them?
Global variables are variables that can be accessed and manipulated anywhere in the
program. To make a variable global, place the variable declaration on the upper portion
of the program, just after the preprocessor directives section.
The gets() function allows a full line data entry from the user. When the user presses
the enter key to end the input, the entire line of characters is stored to a string variable.
Note that the enter key is not included in the variable, but instead a null terminator \0 is
placed after the last character.
32 keywords.