Sunday, 4 December 2016

Adobe CWB Test - HackerRank

This test consisted of 18 questions that test your C programming skills - It includes 4 coding questions and the rest are MCQs. Please comment your answers below

Q1 What will be the output of the following C program?
int main() {
  int x = 10, y = 20;
  if (!(!x) && x) {
    printf("x = %d\n", x);
  else
    printf("y = %d\n", y);
  return 0; 
}
Pick the correct choice below
y = 20
x = 0
x = 10
x = 1



Q2 What will be the output of the program?
int main() {
  enum days {MON, TUE, WED=6, THU, FRI=-1, SAT};
  printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);
  return 0;
}

Pick the correct choice below
6, 6, 6, 7, -1, -1
1, 2, 6, 7, -1, 0
4, 5, 6, 7, -1, 0
0, 1, 6, 7, -1, 0

Q3 What will  be the output of the following code?
#define max 10
void main() {
  int i;
  i=++max;
  clrscr();
  printf("%d", i);
  getch();
}

Pick the correct choice below
10
11
0
Compilation Error

Q4 What will be the output of the following C program?
int main() {
  int _ = 10;
  int __ = 5;
  int ___;
  ___ = _ - __;
 printf("%i", ___);
 return 0;
}

5
-5
0
Compilation Error

Q5 What will the following code print when executed?
double x = -3.5, y = 3.5
printf("%.0f : %.0f\n", ceil(x), ceil(y));
printf("%.0f : %.0f\n", floor(x), floor(y));

Q6 Assuming a short is two bytes long, what will be printed by the following code?
short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} };
printf("%d\n", sizeof(testarray));

It will not compile because not enough initializers are given.


Q7 What will be printed when the sample code is executed?
int y[4] = {6, 7, 8, 9};
int *ptr = y + 2;
printf("%d\n", ptr[1]);  /*ptr+1 == ptr[1] */


Q8 What will be printed when the sample code is executed?
 int i = 4;
int x = 6;
z = x/i;
printf("z=%.2f\n", z);


Q9 Which one of the following can replace the ???? in the code below?
FILE *f = fopen(fileName, "r");
readData(f);
if ( ???? )
  puts("End of file was reached");

Q10 What will the code below print when it is executed?
#include
void func() {
  int x = 0;
  static int y = 0;
  x++; ++y;
  printf("%d -- %d\n", x, y);
}

int main() {
 func();
 func();
 return 0;
}


Q11 What is the result of 4 << 2 ?

Q12 In a program, using the 'rand' function you can generate a fixed sequence of random numbers every time the program is run. How do you make the sequence different in each run?

Q13 Write a C program to convert a binary number entered as a string of 0's and 1's, to a decimal number.

Q14 Write a program in C to print the pattern of a triangle exactly as below, using the character *, (you must use loops)
*********
  *******
    *****
      ***
        *

Q15 Given two 2x2 arrays as two matrices, you have to create a third array as the product of these two matrices(Matrix multiplication). Write the loop for the same.

No comments :

Post a Comment