1) What are different types of modifiers in C?
There are 5 modifiers available in C language. They are: short, long, signed, unsigned, and long long
There are 5 modifiers available in C language. They are: short, long, signed, unsigned, and long long
2) What is a static variable?
A static local variable retains its value between the function call and the default value is 0.
A static local variable retains its value between the function call and the default value is 0.
3) a++ or a = a+1, which can be recommended to increment the value by 1 and why?
a++, as it is single machine instruction internally.
a++, as it is single machine instruction internally.
4) What is a dangling pointer?
A pointer initially holding a valid address, but later the held address is released or freed. Then
such a pointer is called as a dangling pointer.
A pointer initially holding a valid address, but later the held address is released or freed. Then
such a pointer is called as a dangling pointer.
5) What are lvalue and rvalue?
The expression appearing on the right side of the assignment operator is called as rvalue. Rvalue is assigned to an lvalue, which appears on the left side of the assignment operator. The lvalue should designate to a variable not a constant.
The expression appearing on the right side of the assignment operator is called as rvalue. Rvalue is assigned to an lvalue, which appears on the left side of the assignment operator. The lvalue should designate to a variable not a constant.
6) Explain the use of %i format specifier w.r.t scanf().
Can be used to input integer in all the supported format.
Can be used to input integer in all the supported format.
7) When to use -> (arrow) operator.
If the structure/union variable is a pointer variable, to access structure/union elements the
arrow operator is used.
If the structure/union variable is a pointer variable, to access structure/union elements the
arrow operator is used.
8) Which built-in library function can be used to re-size the allocated dynamic memory?
realloc().
realloc().
9) What is typecasting?
Typecasting is a way to convert a variable/constant from one type to another type.
Typecasting is a way to convert a variable/constant from one type to another type.
10) What is meant by Compilation?
The process of translating source code written in high level to low-level machine code is called
as Compilation. The compilation is done by special software known as a compiler. The compiler
checks source code for any syntactical or structural errors and generates object code with
extension .obj (in Windows) or .o (in Linux) if source code is error free.
The process of translating source code written in high level to low-level machine code is called
as Compilation. The compilation is done by special software known as a compiler. The compiler
checks source code for any syntactical or structural errors and generates object code with
extension .obj (in Windows) or .o (in Linux) if source code is error free.
11) What are the stages in C compilation?
Preprocessing, Compilation, Assembling and Linking.
Preprocessing, Compilation, Assembling and Linking.
12) What do you mean by pre-processing a source file?
The C compilation begins with pre-processing of a source file. Pre-processor is a small software
that accepts C source file and performs below tasks.
– Remove comments from the source code.
– Macro expansion.
– Expansion of included header files.
After pre-processing, it generates a temporary file with .i extension. Since it inserts the contents of header files to our source code file. Pre-processor generated file is larger than the original
source file.
The C compilation begins with pre-processing of a source file. Pre-processor is a small software
that accepts C source file and performs below tasks.
– Remove comments from the source code.
– Macro expansion.
– Expansion of included header files.
After pre-processing, it generates a temporary file with .i extension. Since it inserts the contents of header files to our source code file. Pre-processor generated file is larger than the original
source file.
13) Difference between the header file and library file.
In simple terms, the library contains function body whereas header file contains function prototype.
In simple terms, the library contains function body whereas header file contains function prototype.
14) What is the difference between far and near pointers?
In the first place, they are non-standard keywords. A near pointer can access only 2^15 memory
space and the far pointer can access 2^32 memory space. Both the keywords are implementation
specific and are non-standard.
In the first place, they are non-standard keywords. A near pointer can access only 2^15 memory
space and the far pointer can access 2^32 memory space. Both the keywords are implementation
specific and are non-standard.
15) What is a ternary operator and define its syntax?
Ternary operator is the same as if else control statement in C.
Syntax : (Condition? true_value: false_value);
Example: (A > 100? 0: 1);
Ternary operator is the same as if else control statement in C.
Syntax : (Condition? true_value: false_value);
Example: (A > 100? 0: 1);
16) Difference between memcpy() and strcpy() functions in C.
memcpy() function is used to copy a specified number of bytes from one memory to another.
Whereas, strcpy() function is used to copy the contents of one string into another string.
memcpy() function acts on memory rather than value. Whereas, strcpy() function acts on value
rather than memory.
memcpy() function is used to copy a specified number of bytes from one memory to another.
Whereas, strcpy() function is used to copy the contents of one string into another string.
memcpy() function acts on memory rather than value. Whereas, strcpy() function acts on value
rather than memory.
17) What is const pointer in C?
Const pointer is a pointer that can’t change the address of the variable that is pointing to. Once
const pointer is made to point one variable, we can’t change this pointer to point to any other
variable. This pointer is called const pointer.
Const pointer is a pointer that can’t change the address of the variable that is pointing to. Once
const pointer is made to point one variable, we can’t change this pointer to point to any other
variable. This pointer is called const pointer.
18) List out some of C compilers.
• clang
• Cygwin
• Digital mars
• GCC compiler
• MikroC Compiler
• clang
• Cygwin
• Digital mars
• GCC compiler
• MikroC Compiler
19) What is the difference between variable declaration and variable definition in C?
· Variable declaration tells the compiler about data type and size of the variable. Whereas, variable definition allocates memory to the variable
· Variable can be declared many times in a program. But, definition can happen only one time for a variable in a program.
· Variable declaration is for assignment of properties and identification to a variable. Whereas, a variable definition is for assignments of storage space to a variable
20) What is enum in C?
· Enumeration is a data type that consists of named integer constants as a list.
· It starts with 0 (zero) by default and value is incremented by 1 for the sequential identifiers in the list.
21) What will i and j equal after the code below is executed?int i = 5; int j = i++;
When these operators precede a variable, the value of the variable is modified first and then the modified value is used. For example, if we modified the above code snippet to instead say int j = ++i;, i would be incremented to 6 and then j would be set to that modified value, so both would end up being equal to 6.However, when these operators follow a variable, the unmodified value of the variable is used and then it is incremented or decremented. That’s why, in the statement int j = i++; in the above code snippet, j is first set to the unmodified value of i(i.e., 5) and then i is incremented to 6.
When these operators precede a variable, the value of the variable is modified first and then the modified value is used. For example, if we modified the above code snippet to instead say int j = ++i;, i would be incremented to 6 and then j would be set to that modified value, so both would end up being equal to 6.However, when these operators follow a variable, the unmodified value of the variable is used and then it is incremented or decremented. That’s why, in the statement int j = i++; in the above code snippet, j is first set to the unmodified value of i(i.e., 5) and then i is incremented to 6.
22) Is there a difference between class and struct?
The only difference between a class and struct are the access modifiers. Struct members are
public by default; class members are private. It is good practice to use classes when you need an
object that has methods and structs when you have a simple data object.
The only difference between a class and struct are the access modifiers. Struct members are
public by default; class members are private. It is good practice to use classes when you need an
object that has methods and structs when you have a simple data object.
23) Explain the volatile and mutable keywords.
The volatile keyword informs the compiler that a variable may change without the compiler knowing it. Variables that are declared as volatile will not be cached by the compiler, and will thus always be read from memory. The mutable keyword can be used for class member variables. Mutable variables are allowed to change from within const member functions of the class.
The volatile keyword informs the compiler that a variable may change without the compiler knowing it. Variables that are declared as volatile will not be cached by the compiler, and will thus always be read from memory. The mutable keyword can be used for class member variables. Mutable variables are allowed to change from within const member functions of the class.
24) How many times will this loop execute? Explain your answer.
unsigned char half_limit = 150;
for (unsigned char i = 0; i < 2 * half_limit; ++i)
{
// do something;
}
Code will result in an infinite loop.Here’s why:
The expression 2 * half_limit will get promoted to an int (based on C++ conversion rules) and will have a value of 300. However, since i is an unsigned char, it is represented by an 8-bit value which, after reaching 255, will overflow (so it will go back to 0) and the loop will, therefore, go on forever.
unsigned char half_limit = 150;
for (unsigned char i = 0; i < 2 * half_limit; ++i)
{
// do something;
}
Code will result in an infinite loop.Here’s why:
The expression 2 * half_limit will get promoted to an int (based on C++ conversion rules) and will have a value of 300. However, since i is an unsigned char, it is represented by an 8-bit value which, after reaching 255, will overflow (so it will go back to 0) and the loop will, therefore, go on forever.
25) What is a main() and difference b/w void main() and int main()?
main() is an entry point ( main function) which is in most programming languages, When compiler begins compile the program, It looks for an entry point, and main() acts as an entry point in C program, or we can say main is a thread/ process/ function that invokes automatically by the compiler when program is being executed.Every function returns a value to the calling function, at that time main will be a called function for compiler/OS and it will return some value to the compiler before exit, here void and int defines that main will return a void (nothing) and int will return an integer value to the compiler.
main() is an entry point ( main function) which is in most programming languages, When compiler begins compile the program, It looks for an entry point, and main() acts as an entry point in C program, or we can say main is a thread/ process/ function that invokes automatically by the compiler when program is being executed.Every function returns a value to the calling function, at that time main will be a called function for compiler/OS and it will return some value to the compiler before exit, here void and int defines that main will return a void (nothing) and int will return an integer value to the compiler.
No comments:
Post a Comment