Ans:
Ans:
Ans: 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.
Ans: Reserved words are words that are part of the standard C language library. This means that reserved words have special meaning and therefore cannot be used for purposes other than what it is originally intended for. Examples of reserved words are int, void, and return.
Ans: A statement that allows executing statement or group of statements in repeated way is defined as a loop. Following diagram explains
There are 4 types of a loop statement in C.
Ans: 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.
Ans: auto, register, static, extern.
Ans: Scope of a variable is the part of the program where the variable may directly be accessible. In C, all identifiers are lexically (or statically) scoped.
Ans: When declaring functions, you will decide whether that function would be returning a value or not. If that function will not return a value, such as when the purpose of a function is to display some outputs on the screen, then void is to be placed at the leftmost part of the function header. When a return value is expected after the function execution, the data type of the return value is placed instead of void.
Ans: A linked list is composed of nodes that are connected with another. In C programming, linked lists are created using pointers. Using linked lists is one efficient way of utilizing memory for storage.
Ans: NULL is used to indicate that the pointer doesn’t point to a valid location. Ideally, we should initialize pointers as NULL if we don’t know their value at the time of declaration. Also, we should make a pointer NULL when memory pointed by it is deallocated in the middle of a program.
Ans: Binary trees are actually an extension of the concept of linked lists. A binary tree has two pointers, a left one and a right one. Each side can further branch to form additional nodes, which each node having two pointers as well.
Ans: Get the two’s compliment of the same positive integer. Eg: 1011 (-5)
Step-1: One’s compliment of 5 : 1010
Step-2: Add 1 to above, giving 1011, which is -5
Ans: Yes, it can be but cannot be executed, as the execution requires main() function definition.
Ans: A structure containing an element of another structure as its member is referred so.
Ans: A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.
Ans: 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;
}
NOTE − A global variable can’t be an automatic variable.
Ans:
Ans: Typecasting is a way to convert a variable/constant from one type to another type.
Ans: On failure fopen() returns NULL, otherwise opened successfully.
Ans: S++, as it is single machine instruction (INC) internally.
Ans: Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated memory with 0’s.
Ans: 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.
Ans: Dividing the program in to sub programs (modules/function) to achieve the given task is modular approach. More generic functions definition gives the ability to re-use the functions, such as built-in library functions.
Ans: It cannot be used on constants. It cannot be used on variable which are declared using register storage class.
Ans: Function definition in C contains four main sections:
Ans: These 2 functions basically perform the same action, which is to get the absolute value of the given value. Abs() is used for integer values, while fabs() is used for floating type numbers. Also, the prototype for abs() is under , while fabs() is under .
Ans: Text files contain data that can easily be understood by humans. It includes letters, numbers and other characters. On the other hand, binary files contain 1's and 0's that only computers can interpret.
Ans: Dynamic data structure provides a means for storing data more efficiently into memory. Using dynamic memory allocation, your program will access memory spaces as needed. This is in contrast to static data structure, wherein the programmer has to indicate a fix number of memory space to be used in the program.
Ans: It is referred to as a terminating null character, and is used primarily to show the end of a string value.
Ans: The = symbol is often used in mathematical operations. It is used to assign a value to a given variable. On the other hand, the == symbol, also known as equal to or equivalent to, is a relational operator that is used to compare two values.
Ans: A local static variable is a variable whose lifetime doesn’t end with a function call where it is declared. It extends for the lifetime of complete program. All calls to the function share the same copy of local static variables. Static variables can be used to count the number of times a function is called. Also, static variables get the default value as 0. For example, the following program prints “0 1”
#include <stdio.h> void fun() { // static variables get the default value as 0. static int x; printf ( "%d " , x); x = x + 1; } int main() { fun(); fun(); return 0; } // Output: 0 1 |
Ans: In C, functions are global by default. The “static” keyword before a function name makes it static. Unlike global functions in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static. Another reason for making functions static can be reuse of the same function name in other files.
Ans: Declaration of a variable/function simply declares that the variable/function exists somewhere in the program but the memory is not allocated for them. But the declaration of a variable/function serves an important role. And that is the type of the variable/function. Therefore, when a variable is declared, the program knows the data type of that variable. In case of function declaration, the program knows what are the arguments to that functions, their data types, the order of arguments and the return type of the function. So that’s all about declaration. Coming to the definition, when we define a variable/function, apart from the role of declaration, it also allocates memory for that variable/function. Therefore, we can think of definition as a super set of declaration. (or declaration as a subset of definition). From this explanation, it should be obvious that a variable/function can be declared any number of times but it can be defined only once. (Remember the basic principle that you can’t have two locations of the same variable/function).
// This is only declaration. y is not allocated memory by this statement
extern int y;
// This is both declaration and definition, memory to x is allocated by this statement.
int x;
Ans:
Ans: Dangling Pointer is a pointer that doesn’t point to a valid memory location. Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. Following are examples.
// EXAMPLE 1 int *ptr = ( int *) malloc ( sizeof ( int )); ............. ............. free (ptr); // ptr is a dangling pointer now and operations like following are invalid *ptr = 10; // or printf("%d", *ptr); |
// EXAMPLE 2 int *ptr = NULL { int x = 10; ptr = &x; } // x goes out of scope and memory allocated to x is free now. // So ptr is a dangling pointer now |
Ans: Null pointers are possible to use in three ways.
Ans:
int main( void ) { if ( printf ( "Hello World" )) ; } |
Ans:
for (a=1; a<=5; i++) {
for (b=1; b<=a; b++)
printf("%d",b);
printf("\n");
}
Ans: A stack is one form of a data structure. Data is stored in stacks using the FILO (First In Last Out) approach. At any particular instance, only the top of the stack is accessible, which means that in order to retrieve data that is stored inside the stack, those on the upper part should be extracted first. Storing data in a stack is also referred to as a PUSH, while data retrieval is referred to as a POP.
Ans: When writing programs that will store and retrieve data in a file, it is possible to designate that file into different forms. A sequential access file is such that data are saved in sequential order: one data is placed into the file after another. To access a particular data within the sequential access file, data has to be read one data at a time, until the right one is reached.
Ans: Comments are a great way to put some remarks or description in a program. It can serves as a reminder on what the program is all about, or a description on why a certain code or function was placed there in the first place. Comments begin with /* and ended by */ characters. Comments can be a single line, or can even span several lines. It can be placed anywhere in the program.
Ans: Debugging is the process of identifying errors within a program. During program compilation, errors that are found will stop the program from executing completely. At this state, the programmer would look into the possible portions where the error occurred. Debugging ensures the removal of errors, and plays an important role in ensuring that the expected program output is met.
Ans: The && is also referred to as AND operator. When using this operator, all conditions specified must be TRUE before the next action can be performed. If you have 10 conditions and all but 1 fails to evaluate as TRUE, the entire condition statement is already evaluated as FALSE.
Related Interview Questions...