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. typedef struct error{int warning, error, exception;}error;
         main()
        {
            error g1;
            g1.error =1; 
            printf("%d",g1.error);
         }

    Answer:

    1

    Explanation:

    The three usages of name errors can be distinguishable by the compiler at any instance, so valid (they are in different namespaces). Typedef struct error{int warning, error, exception;}error; This error can be used only by preceding the error by struct kayword as in: struct error someError; typedef struct error{int warning, error, exception;}error; This can be used only after . (dot) or -> (arrow) operator preceded by the variable name as in : g1.error =1;
    printf("%d",g1.error);
    typedef struct error{int warning, error, exception;}error;
    This can be used to define variables without using the preceding struct keyword as in: error g1; Since the compiler can perfectly distinguish between these three usages, it is perfectly legal and valid.

    Note

    This code is given here to just explain the concept behind. In real programming don't use such overloading of names. It reduces the readability of the code. Possible doesn't mean that we should use it!
  2. #ifdef something
    int some=0;
    #endif
    
    main()
    {
    int thing = 0;
    printf("%d %d\n", some ,thing);
    }

    Answer:

    Compiler error : undefined symbol some

    Explanation:

    This is a very simple example for conditional compilation. The name something is not already known to the compiler making the declaration int some = 0; effectively removed from the source code.
  3. #if something == 0
    int some=0;
    #endif
    
    main()
    {
    int thing = 0;
    printf("%d %d\n", some ,thing);
    }

    Answer:

    0 0

    Explanation:

    This code is to show that preprocessor expressions are not the same as the ordinary expressions. If a name is not known the preprocessor treats it to be equal to zero.
  4. void main()
             {
    if(~0 == (unsigned int)-1)
    printf("You can answer this if you know how values are represented in memory");
             }

    Answer

    You can answer this if you know how values are represented in memory

    Explanation

    ~ (tilde operator or bit-wise negation operator) operates on 0 to produce all ones to fill the space for an integer. -1 is represented in unsigned value as all 1's and so both are equal.
  5. int swap(int *a,int *b)
    {
     *a=*a+*b;*b=*a-*b;*a=*a-*b;
    }
    main()
    {
    		int x=10,y=20;
    	swap(&x,&y);
    		printf("x= %d y = %d\n",x,y);
    }

    Answer:

    x = 20 y = 10

    Explanation

    This is one way of swapping two values. Simple checking will help understand this.

« 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.