Sample Questions Best site for GRE, LSAT, SAT, GMAT, TOEFL, CCNA, CCSA and interview sample questions  

Technical Sample Questions : C |  C++ |  Oracle |  Java | Unix |  Operating Systems |  Data Structure

Sample Technical Questions

C Sample Question

  1. 	main()
    {
    	unsigned int i=65000;
    	while(i++!=0);
    	printf("%d",i);
    }

    Answer:

    1

    Explanation:

    Note the semicolon after the while statement. When the value of i becomes 0 it comes out of while loop. Due to post-increment on i the value of i while printing is 1.
  2. main()
    {
    	int i=0;
    	while(+(+i--)!=0)
    		i-=i++;
    	printf("%d",i);
    }

    Answer:

    -1

    Explanation:

    Unary + is the only dummy operator in C. So it has no effect on the expression and now the while loop is, while(i--!=0) which is false and so breaks out of while loop. The value –1 is printed due to the post-decrement operator.
  3. main()
    {
    	float f=5,g=10;
    	enum{i=10,j=20,k=50};
    	printf("%d\n",++k);
    	printf("%f\n",f<<2);
    	printf("%lf\n",f%g);
    	printf("%lf\n",fmod(f,g)); 
    }

    Answer:

    Line no 5: Error: Lvalue required
    Line no 6: Cannot apply leftshift to float
    Line no 7: Cannot apply mod to float

    Explanation:

    Enumeration constants cannot be modified, so you cannot apply ++.
    Bit-wise operators and % operators cannot be applied on float values.
    fmod() is to find the modulus values for floats as % operator is for ints.
  4. main()
    {
    	int i=10;
    	void pascal f(int,int,int);
    f(i++,i++,i++);
    	printf(" %d",i);
    }
    void pascal f(integer :i,integer:j,integer :k)
    { 
    write(i,j,k); 
    }

    Answer:

    Compiler error: unknown type integer Compiler error: undeclared function write

    Explanation:

    Pascal keyword doesn’t mean that pascal code can be used. It means that the function follows Pascal argument passing mechanism in calling the functions.
  5. void pascal f(int i,int j,int k)
    { 
    printf(“%d %d %d”,i, j, k); 
    }
    void cdecl f(int i,int j,int k)
    { 
    printf(“%d %d %d”,i, j, k); 
    }
    main()
    {
    	int i=10;
    f(i++,i++,i++);
    	printf(" %d\n",i);
    i=10;
    f(i++,i++,i++);
    printf(" %d",i);
    }

    Answer:

    10 11 12 13
    12 11 10 13

    Explanation:

    Pascal argument passing mechanism forces the arguments to be called from left to right. cdecl is the normal C argument passing mechanism where the arguments are passed from right to left.

« Previous || Next »

C Sample Question Number : 1-3 | 4-7 | 8-11 | 12-16 | 17-21 | 22-25 | 26-30 | 31-35 | 36-40 | 41-45 | 46-48 | 49-52 | 53-59 | 60-64 | 65-69 | 70-74 | 75-79 | 80-83 | 84-87 | 88-91 | 92-95 | 96-100 | 101-105 | 106-110 | 111-115 | 116-120 | 121-125 | 126-130 | 131-135 | 136-140 | 141-145 | 146-150

Sample Test Questions
GRE Sample Questions
CAT Sample Questions
GMAT Sample Questions
TOEFL Sample Questions
ACT Sample Questions
SAT Sample Questions
LSAT Sample Questions
PSAT Sample Questions
MCAT Sample Questions
PMP Sample Questions
GED Sample Questions
ECDL Sample Questions
DMV Sample Questions
CCNA Sample Questions
MCSE Sample Questions
Network+ Sample Questions
A+ Sample Questions
Technical Sample Questions
WASL Sample Questions
CISA Sample Questions

Other Sample Questions
Sample Interview Questions
Sample Teacher Interview Questions
Sample Citizenship Questions
Accuplacer Sample Questions
Science Bowl sample Questions
Driving Test Sample Questions
Sample Survey Questions Sample Essay Questions
Sample Behavioral Interview Questions

Copyright © 2004-2013, Best BSQ. All Rights Reserved.