C Interview Questions - 4
Thursday, November 29, 2007
11. What will be printed as the result of the operation below:
main()
{
int x=10, y=15;
x = x++;
y = ++y;
printf(“%d %d\n”,x,y);
}
Answer: 11, 16
12. What will be printed as the result of the operation below:
main()
{
int a=0;
if(a==0)
printf(“MindgrillQ Systems\n”);
printf(“MindgrillQ Systems\n”);
}
Answer: Two lines with “MindgrillQ Systems” will be printed.
13. Write a function that swaps the values of two integers, using int* as the argument type.
void swap(int* a, int*b)
{
int t;
t = *a;
*a = *b;
*b = t;
}
14. Write a program that ask for user input from 5 to 9 then calculate the average
#include "iostream.h"
int main()
{
int MAX = 4;
int total = 0;
int average;
int numb;
for (int i=0; icout << "Please enter your input between 5 and 9: ";
cin >> numb;
while ( numb<5>9)
{
cout << "Invalid input, please re-enter: ";
cin >> numb;
}
total = total + numb;
}
average = total/MAX;
cout << "The average number is: " << return 0;
}
0 comments:
Post a Comment