Egs on unsigned integer
#include
main(){
unsigned int i;
for(i=1;i>-2;i–)
printf(“c aptitude”);
}
Explanation:
i is an unsigned integer. It is compared with a signed value. Since the both
types doesn’t match, signed is promoted to unsigned value. The unsigned
equivalent of -2 is a huge value so condition becomes false and control
comes out of the loop.
**#include
int main()
{
unsigned giveit=-1;
[Read More]
Extern keyword
main()
{
extern int i;
i=20;
printf("%d”,sizeof(i));
}
Answer:
Linker error: undefined symbol ‘_i’.
Explanation:
extern declaration specifies that the variable i is defined somewhere else.
The compiler passes the external variable to be resolved by the linker. So
compiler doesn’t find an error. During linking the linker searches for the
definition of i. Since it is not found the linker flags an error.
2)
main()
{
[Read More]
Using ## and # with define.
Stringize(#)
#define message\_for(a, b) \\
printf(#a " and " #b)
int main()
{
message\_for(Carole, Debra);
}
**Token pasting (##)**
#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
**Answer:**
100Return values of some functions in c
scanf
**scanf("%d” , & i); //10 is given as input
**
Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should have been scanned successfully. So number of items read is 1.
printf
Upon a successful return, the printf() function returns the number of characters printed (not including the trailing ‘\0’ used to end output to strings). If the output was truncated due to this limit then the return value is the number of characters (not including the trailing ‘\0’) which would have been written to the final string if enough space had been available.
[Read More]
The preprocessor directives can be redefined anywhere in the program
#include
#define a 10
main()
{
#define a 50
printf("%d”,a);
}
Answer:
50
Explanation:
The preprocessor directives can be redefined anywhere in the program. So
the most recently assigned value will be taken.
Given a rectangular (cuboidal for the puritans) cake with a rectangular piece removed (any size or orientation), how would you cut the remainder of the cake into two equal halves with one straight cut of a knife ?
The cut (plane) should pass through the center of the two rectangles: the outer cake and the inner hollow area. Since any plane passing through the center of the cuboid will divide the volume in two halves, both the cake and hollow area are divided into two equal halves.
How does throwing and catching exceptions differ from using setjmp and longjmp?
The throw operation calls the destructors for automatic objects instantiated since entry to the try block.
Exceptions are in the mainstream of C++ now, so most programmers, if they are familiar with setjmp and longjmp, should know the difference. Both idioms return a program from the nested depths of multiple function calls to a defined position higher in the program. The program stack is “unwound” so that the state of the program with respect to function calls and pushed arguments is restored as if the calls had not been made.
[Read More]
What is the difference between goto and longjmp() and setjmp()?
A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind should be avoided because it is not considered good programming practice to use such statements as goto and longjmp in your program.
A goto statement simply bypasses code in your program and jumps to a predefined position. To use the goto statement, you give it a labeled position to jump to.
[Read More]
Besides communication cost, what is the other source of inefficiency in RPC?
context switches, excessive buffer copying.
How can you optimise the communication?
(ans : communicate through shared memory on same machine, bypassing the kernel
Given an eight-bit bitmap graphics file, devise an algorithm to convert the file into a two-bit ASCII approximation
Assume that the file format is one byte for every pixel in the file, and that the approximation will produce one ASCII character of output for each pixel. This problem is easier to solve than it sounds. This is one of the tricks used in technical interview questions. Problems may be obscured or made to sound difficult. Don’t be fooled! Take the time to think about the core of the problem.
[Read More]