Thursday, July 18, 2013

C Programming Questions and Answers, C Interview Questions, GATE previous year Questions in C Programming

Hello friend, In this post I am going to create a huge collection of all types of Questions with Answers. Wherever I will find any question that is important for GATE or any interview, I will post it here

For programming in C/ C++, you can use Dev C++ IDE, it is free IDE for C and C++ developer, Link to download


Q. What is the difference between the declaration and definition of a variable?

Ans: The definition is the one that actually allocate space, and provides an initialization value, if any. There can be many declaration, but there must be exactly one definition

Q. What is the difference between a statement and a block?

Ans: A statement is single C expression terminated with a semicolon. A block is a series of statements, the group of which is inclosed in curly braces.

Q. How to add two numbers without using arithmetic operators?

OR

Q. Write a function that returns sum of two integers. The function should not use any of the arithmetic operators (+, ++, -, --, .. etc).

Ans: We can not use arithmetic operator but we can use C Bitwise Operators, below is the function that will add two number without using arithmetic operators

int AddNumbers(int x, int y)
{
    if (y == 0)
        return x;
    else
        return AddNumbers( x ^ y, (x & y) << 1);
}

Q. How many squares does a chess-board contain?

Ans: Total number of squares = 8²+7²+...+1² = 204
This concept can be generalized to calculate number of squares in any N*N matrix
1² + 2² + 3² + ....n² = n(n+1)(2n+1)/6

Q. How many rectangles does a chess-board contain?

Ans: Total = [n(n+1)/2]^2
Here n is 8

No comments:

Post a Comment