[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Technical Interview Questions and Answers :: C

    1 / 123

    What is the difference between ++var and var++?

    The ++ operator is called the increment operator. When the operator is placed before the variable (++var), the variable is incremented by 1 before it is used in the expression. When the operator is placed after the variable (var++), the expression is evaluated, and then the variable is incremented by 1.

    The same holds true for the decrement operator (--). When the operator is placed before the variable, you are said to have a prefix operation. When the operator is placed after the variable, you are said to have a postfix operation.

    For instance, consider the following example of postfix incrementation:

    int x, y;
    x = 1;
    y = (x++ * 5);

    In this example, postfix incrementation is used, and x is not incremented until after the evaluation of the expression is done. Therefore, y evaluates to 1 times 5, or 5. After the evaluation, x is incremented to 2.

    Now look at an example using prefix incrementation:

    int x, y;
    x = 1;
    y = (++x * 5);

    This example is the same as the first one, except that this example uses prefix incrementation rather than postfix. Therefore, x is incremented before the expression is evaluated, making it 2. Hence, y evaluates to 2 times 5, or 10.

    Please Login First :

    2 / 123

    How can you rate yourself in C on a scale of 10?

    On what basis u have rated. It might be depend on the question

    Please Login First :

    3 / 123

    What is a local block?

    A local block is any portion of a C program that is enclosed by the left brace ({) and the right brace (}). A C function contains left and right braces, and therefore anything between the two braces is contained in a local block. An if statement or a switch statement can also contain braces, so the portion of code between these two braces would be considered a local block.

    Additionally, you might want to create your own local block without the aid of a C function or keyword construct. This is perfectly legal. Variables can be declared within local blocks, but they must be declared only at the beginning of a local block. Variables declared in this manner are visible only within the local block. Duplicate variable names declared within a local block take precedence over variables with the same name declared outside the local block. Here is an example of a program that uses local blocks:

    void main(void);
    void main()
    /* Begin local block for function main() */
    int test_var = 10;
    printf("Test variable before the if statement: %d\n", test_var);
    if (test_var > 5)
    /* Begin local block for "if" statement */
    int test_var = 5;
    printf("Test variable within the if statement: %d\n",
    /* Begin independent local block (not tied to
    any function or keyword) */
    int test_var = 0;
    "Test variable within the independent local block:%d\n",
    /* End independent local block */
    /* End local block for "if" statement */
    printf("Test variable after the if statement: %d\n", test_var);
    /* End local block for function main() */

    This example program produces the following output:

    Test variable before the if statement: 10

    Test variable within the if statement: 5

    Test variable within the independent local block: 0

    Test variable after the if statement: 10

    Notice that as each test_var was defined, it took precedence over the previously defined test_var. Also notice that when the if statement local block had ended, the program had reentered the scope of the original test_var, and its value was 10.

    Please Login First :

    4 / 123

    Should variables be stored in local blocks?

    The use of local blocks for storing variables is unusual and therefore should be avoided, with only rare exceptions. One of these exceptions would be for debugging purposes when you might want to declare a local instance of a global variable to test within your function. You also might want to use a local block when you want to make your program more readable in the current context. Sometimes having the variable declared closer to where it is used makes your program more readable. However, well-written programs usually do not have to resort to declaring variables in this manner, and you should avoid using local blocks.

    Please Login First :

    5 / 123

    When is a switch statement better than multiple if statements?

    A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type.

    Please Login First :

    6 / 123

    Is a default case necessary in a switch statement?

    No switch cases can exist with out default case, in switch case default case will trigger when it is not  match with any other case values.

    Please Login First :

    7 / 123

    Can the last case of a switch statement skip including the break?

    it's optinal because last case is defaut statement no need the default statement neceesary.

    Please Login First :

    8 / 123

    How can you tell whether a loop ended prematurely?

    If a break is used in a loop. like below

    i = 0

    while (i < 10)


    if (i == 3)



    Please Login First :

    9 / 123

    What does the modulus operator do?

    Modulus operator % calculates the remainder when used
    say a%b will find the remainder when the number a is divided b .

    Please Login First :

    10 / 123

    What is meant by "bit masking"?

    Bitmasking refers to the technique of representing a subset of a set using bits of a number .
    for eg suppose we have n numbers {1,2,3,4,5,6,7,8} in an array

    then a bitmask to indicate the subset{2,3,6} of the above set will be a set of binary values like {0,1,1,0,0,1,0,0} where 1 indicates element at ith index belong to set and 0 indicated that it doesnt.

    this 0,1 information can also be stored in bits of a number.

    for eg consider a number mask=0;

    if we want to set the ith bit of mask to 1 we can apply following operation

    mask = mask|(1<
    where '|' is bitwise or and '<<' is bitwise left shift operator
    and the ith bit will become 1 indicating the number is included in the set
    similarly to remove a number from the set following operating can be performed
    mask = mask^(1< where '^' is bitwise xor operator

    Please Login First :

Frequently asked C Language Technical Interview Questions and Answers - Q4Interveiw.com at Freshers and experience level. All Question are based on the real time experience of previous candidates. You can search and filter the question set by company name from the tag cloud.

Q4I Collection of C Programming Interview Questions and Answers with Explanations asked in campus/off-campus interviews, walk-in interview and various IT companies Interview at Freshers & Experienced level. Multiply your selection chance by practicing the C Interview Question from basic to Standard, or by going through Company specific pattern of question asked from C Programming.

So, next time, when you prepare for a company's interview, please check your knowledge against these C language technical interview questions and answers.