PuzzlersWorld.com

  • Hacker Puzzle
  • Interview Puzzles
  • Number Puzzles
  • Maths Puzzles

Objective Questions set C/C++ – Part 4

(1 votes, average: 1.00 out of 5)

October 28, 2012 by asinghal 5 Comments

10 Objective type interview questions with answers on C/C++

Before you start:-

  1. You can check your answer by filling a,b,c,d or e in the text box.
  2. You can get the answer by clicking Give Up Button.

Try yourself before giving up 🙂

Q1)

#include
main()
{
    unsigned char i;
    int sum=0;
    for(i=0;i<300;i++)
        sum=sum+i;
    printf("%d",sum);
}

Options: a) 44850 b) 45150 c) 300 d) Infinite Loop

Tried enough already?

Q2)

#include
fun(int i)
{
    int j=0;
    while (i & i-1) {
        j++;   
    }
    printf("%d",j);
}

main(){
    f(100);
}

Options: a. 100 b. 99 c. 2 d. 3

Tried enough already?

Q3)

Code 1 :
        for(i=0; i<1000; i++)
                for(j=0; j<100; j++)
                        x = y;

Code 2 :
        for(i=0; i<100; i++)
                for(j=0; j<1000; j++)
                        x = y;

Which code will execute faster ?


Options:
a) Code 1 and Code 2 are of same speed,
b) Code 1,
c) Code 2,
d) Can’t Say
Tried enough already?

Q4)

main()
{
    int a[10] = {1, 2, 3, ...., 10}, i, x=10, temp;
    for(i=0; i < x; i++){
        temp = a[i];
        a[i] = a[x-i-1];
        a[x-i-1] = temp;
    }
}

What happens to the elements of the array a ?
a) Reversed
b) Only some portions are altered
c) Remains same
d) None

Tried enough already?

Q5)

#include
# define MAX(a, b) a>b ? a:b
main()
{
    int m, n;
    m = 3 + MAX(2, 3);
    n = 2 * MAX(3, 2);
    printf("%d, %d\n", m, n);
}

Options: a) 6, 6 b) 5, 6 c) 2, 3 d) None

Tried enough already?

Q6)

#include
main(){
        int i=10;
        printf("%d %d %d",i,++i,i++);
}

a).10 11 12
b).12 11 10
c).10 11 11
d).12 12 10

Tried enough already?

Q7)
What is the size of ‘q’ in the following program?

union{  
    int x;
    char y;
    struct {
	char x;
	char y;
	int xy;
    }p;
}q;

Options:
a)11
b)6
c)4
d)5
e)none

Tried enough already?

Q8)
Result of the following program is ?

main()
{
    int i=0;
    for(i=0;i<20;i++)
    {
        switch(i)
	{
	    case 0:i+=5;
	    case 1:i+=2;
	    case 5:i+=5;
	    default  i+=4;
	    break;
        }
	printf("%d,",i);
    }
}

Options:
a)0,5,9,13,17,
b)5,9,13,17,
c)12,17,22,
d)16,21,
e)syntax error

Tried enough already?

Q9)

#include
main()
{
    char *p1="name";
    char *p2;
    p2=(char*)malloc(20);
    while(*p2++ = *p1++);
    printf("%s\n",p2);
}

Options: a) name b) n c) ame d) Empty String

Tried enough already?

Q10)

#include
main()
{
    int x=20,y=35;
    x=y++ + x++;
    y= ++y + ++x;
    printf("%d %d\n",x,y);
}

Options: a) 55 94 b) 56 94 c) 57 94 d) None

Tried enough already?
  • Share on Whatsapp
  • Share on Facebook
  • Share on Twitter
Facebook Comments
Next Puzzle
Objective Questions set C/C++ – Part 5

Checkout more Interview Questions Tags: C/C++, Interview, Solved Puzzles

Comments

  1. Div Ya says

    June 17, 2015 at 7:56 pm

    Explain 10th question

    Reply
  2. Ausaf jafri says

    December 27, 2012 at 1:55 pm

    how……….1st quest have infinite loop,???????????????

    Reply
    • puzzlersworld says

      December 30, 2012 at 2:16 pm

      @bc42db8149b30a88b769066d3152364c:disqus its a tricky one :), i is declared as unsigned char, it can hold maximum value of 256, increasing it further will reduce the value back to 0, it will never reach 300 and for loop condition will always be satisfied.

      Reply
  3. k says

    November 14, 2012 at 1:06 pm

    Explain 5th question

    Reply
    • admin says

      November 15, 2012 at 7:25 pm

      In C/C++ MACRO’s are replaced at compile time as it is.
      so m = 3 + MAX(2, 3);
      will become
      m = 3 + 2>3 ? 2:3
      this will evaluate to 5 >3 ? 2:3, thus m will be 2

      Simillarly
      n = 2 * MAX(3, 2); will become
      n = 2 * 3>2 : 3:2 => 6>2 ? 3:2 thus n will be 3

      Reply

Leave a Comment Cancel reply

Submit your Puzzle

You may also like

  • Rotate an array by k elements
  • Cake Cutting solution: Facebook hacker cup 2013 Round 2
  • Reverse a link list without using another
  • Fair and Square Solution: Google codejam 2013 Qual Round
  • Falling Diamonds Solution: Google codejam 2013 Round 1B
  • RoboElection solution: Facebook hacker cup 2013 Round 2
  • Consonants Solution: Google codejam 2013 Round 1C
  • DS with insert, delete and getRandomElement in O(1)
  • Beautiful Strings solution: Facebook hacker Cup 2013 Qual Round
  • Basic Concepts C/C++

Categories

  • Aive hi Puzzles
  • Akbar and Birbal
  • Alphabetical Puzzles
  • Bollywood Puzzles
  • Google Code jam
  • Hindi Riddles
  • Interview Puzzles
  • Interview Questions
  • Logical Puzzles
  • Malayalam Puzzles
  • Maths Puzzles
  • Miscellaneous
  • Number Puzzles
  • Picture Puzzles
  • Riddles
  • Tamil Puzzles
  • Technical

Social

  • View puzzlersworld’s profile on Twitter
privacy policy

Copyright © 2025 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in

  • Hacker Puzzle
  • Logo Puzzles
  • Optical Illusions
  • WhatsApp Puzzles
  • Picture Puzzles
  • Riddles
    â–¼
    • Hindi Riddles
  • Bollywood Puzzles
  • Alphabetical Puzzles
  • Aive hi Puzzles
  • Interview Puzzles
  • Logical Puzzles
  • Interview Questions
    â–²
    • Data Structures
    • Binary Tree
    • Algorithms
    • Recursion Questions
    • Amazon Interview Questions
    • Snapdeal Interview Questions
    • Google Code jam
  • Technical
  • Akbar and Birbal
  • Number Puzzles
  • Maths Puzzles
  • Miscellaneous