Friday 15 March 2013

printf("%d..%d");


main()
{
 int i=400,j=300;
 printf("%d..%d");
}
Answer:
400..300
Explanation:
printf takes the values of the first two assignments of the program. Any number of printf's may be given. All of them take only the first two values. If more number of assignments given in the program,then printf will take garbage values.



Blog Author: Vijay Kumar

Go to: Java Aptitude

C Language Implementation quantities

— 127 nesting levels of blocks
— 63 nesting levels of conditional inclusion
— 12 pointer, array, and function declarators (in any combinations) modifying an arithmetic, structure, union, or incomplete type in a declaration
— 63 nesting levels of parenthesized declarators within a full declarator
— 63 nesting levels of parenthesized expressions within a full expression
— 63 significant initial characters in an internal identifier or a macro name (each universal character name or extended source character is considered a single character)
— 31 significant initial characters in an external identifier (each universal character name
specifying a short identifier of 0000FFFF or less is considered 6 characters, each universal character name specifying a short identifier of 00010000 or more is considered 10 characters, and each extended source character is considered the same number of characters as the corresponding universal character name, if any)
— 4095 external identifiers in one translation unit
— 511 identifiers with block scope declared in one block
— 4095 macro identifiers simultaneously defined in one preprocessing translation unit
— 127 parameters in one function definition
— 127 arguments in one function call

— 127 parameters in one macro definition
— 127 arguments in one macro invocation
— 4095 characters in a logical source line
— 4095 characters in a character string literal or wide string literal (after concatenation)
— 65535 bytes in an object (in a hosted environment only)
— 15 nesting levels for #included files
— 1023 case labels for a switch statement (excluding those for any nested switch statements)
— 1023 members in a single structure or union
— 1023 enumeration constants in a single enumeration
— 63 levels of nested structure or union definitions in a single struct-declaration-list



Blog Author: Vijay Kumar

Go to: Java Aptitude

C++ Language Implementation quantities

— Nesting levels of compound statements, iteration control structures, and selection control structures [256].
— Nesting levels of conditional inclusion [256]. 
— Pointer, array, and function declarators (in any combination) modifying an arithmetic, structure, union, or incomplete type in a declaration [256]. 
— Nesting levels of parenthesized expressions within a full expression [256]. 
— Number of characters in an internal identifier or macro name [1 024]. 
— Number of characters in an external identifier [1 024]. 
— External identifiers in one translation unit [65 536]. 
— Identifiers with block scope declared in one block [1 024]. 
— Macro identifiers simultaneously defined in one translation unit [65 536]. 
— Parameters in one function definition [256].
— Arguments in one function call [256].
 
— Parameters in one macro definition [256]. 
— Arguments in one macro invocation [256]. 
— Characters in one logical source line [65 536]. 
— Characters in a character string literal or wide string literal (after concatenation) [65 536]. 
— Size of an object [262 144]. 
— Nesting levels for #include files [256]. 
— Case labels for a switch statement (excluding those for any nested switch statements) [16 384]. 
— Data members in a single class, structure, or union [16 384].
— Enumeration constants in a single enumeration [4 096]. 
— Levels of nested class, structure, or union definitions in a single struct-declaration-list [256]. 
— Functions registered by atexit()[32]. 
— Direct and indirect base classes [16 384]. 
— Direct base classes for a single class [1024]. 
— Members declared in a single class [4 096].
— Final overriding virtual functions in a class, accessible or not [16 384]. 
— Direct and indirect virtual bases of a class [1 024]. 
— Static members of a class [1 024]. 
— Friend declarations in a class [4 096]. 
— Access control declarations in a class [4 096]. 
— Member initializers in a constructor definition [6 144]. 
— Scope qualifications of one identifier [256]. 
— Nested external specifications [1 024]. 
— Template arguments in a template declaration [1 024]. 
— Recursively nested template instantiations [17]. 
— Handlers per try block [256]. 
— Throw specifications on a single function declaration [256].




Blog Author: Vijay Kumar

Go to: Java Aptitude

enum colors {BLACK,BLUE,GREEN}


enum colors {BLACK,BLUE,GREEN}
 main()
{
 
 printf("%d..%d..%d",BLACK,BLUE,GREEN);
  
 return(1);
}
Answer:
0..1..2
Explanation:
enum assigns numbers starting from 0, if not explicitly defined.



Blog Author: Vijay Kumar

Go to: Java Aptitude

No output/error


main()
{
clrscr();
}
clrscr();
   
Answer:
No output/error
Explanation: The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function).


Blog Author: Vijay Kumar

Go to: Java Aptitude

printf("%p",main);


main()
{
printf("%p",main);
}
Answer:
         Some address will be printed.
Explanation:
    Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They are printed as hexadecimal numbers.


Blog Author: Vijay Kumar

Go to: Java Aptitude

#define clrscr() 100


#define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}
Answer:
100
Explanation:
Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs.The input  program to compiler looks like this :
         main()
         {
              100;
              printf("%d\n",100);
         }

    Note:  100; is an executable statement but with no action. So it doesn't give any problem



Blog Author: Vijay Kumar

Go to: Java Aptitude

#define a 10 and #define a 50


#include <stdio.h>
#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.



Blog Author: Vijay Kumar

Go to: Java Aptitude

++*p++;


main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s   %s",p,p1);
}
Answer:
ibj!gsjfoet
    Explanation:
         ++*p++ will be parse in the given order
Ø *p that is value at the location currently pointed by p will be taken
Ø ++*p the retrieved value will be incremented
Ø when ; is encountered the location will be incremented that is p++ will be executed
Hence, in the while loop initial value pointed by p is ‘h’, which is changed to ‘i’ by executing ++*p and pointer moves to point, ‘a’ which is similarly changed to ‘b’ and so on. Similarly blank space is converted to ‘!’. Thus, we obtain value in p becomes “ibj!gsjfoet” and since p reaches ‘\0’ and p1 points to p thus p1 does not print anything. 



Blog Author: Vijay Kumar

Go to: Java Aptitude

#define square(x) x*x


#define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
Answer:
64
Explanation:
the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64



Blog Author: Vijay Kumar

Go to: Java Aptitude

printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);


 main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
Answer:
45545
Explanation:
The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the  evaluation is from right to left, hence the result.


Blog Author: Vijay Kumar

Go to: Java Aptitude