0% found this document useful (0 votes)
273 views14 pages

Protected: CLA: Part 1 Summary Test: The Program Outputs 0

The program declares an integer pointer variable a and integer variable b, initializes b to 1, sets a to point to b, and prints b, so the output is 1.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
273 views14 pages

Protected: CLA: Part 1 Summary Test: The Program Outputs 0

The program declares an integer pointer variable a and integer variable b, initializes b to 1, sets a to point to b, and prints b, so the output is 1.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Protected: CLA: Part 1 Summary 

Test
What happens if you try to compile and run this program?

1
#include <stdio.h>
2 int main(void) {
3     int i = 1, j = 1, k = -1;
4     k = !i | j;
5     k = !k;
    printf("%d",k);
6
    return 0;
7 }
8

 the program outputs -1


 the program outputs 0
 the program outputs 1
 the program outputs 2

What is the value of the  c  variable at the end of the following snippet?

1
2 #include <stdio.h>
3 int main(void) {
    int a, b, c;
4     a = -1;
5     b = 2;
6     if(a)
7         a--;
8     if(b)
        b++;
9     c = a * b;
10     printf("%d",c);
11     return 0;
12 }
13

 -6
 0
 1
 6
What happens if you try to compile and run this program?

1
2 #include <stdio.h>
3 int main(void) {
    int i = 2, j = 0;
4
 
5     switch (i + 5) {
6     case 1: j++;
7     case 2: j++;
8     default:j = 5;
    case 0: j++; break;
9
    }
10     printf("%d", j);
11     return 0;
12 }
13

 the program outputs 2


 the program outputs 5
 the program outputs 6
 the program outputs 10

What happens if you try to compile and run this program?

1
#include <stdio.h>
2 int main(void) {
3     int i = 1, j = 0, k;
4     k = (i >> j) + (j >> i) + (i >> i) + (j >> j);
5     k <<= i;
    printf("%d", k);
6     return 0;
7 }
8

 the program outputs 0


 the program outputs 1
 the program outputs 2
 the program outputs 4

What happens if you try to compile and run this program?


1
2 #include <stdio.h>
#include <string.h>
3 struct S {
4     char S[8];
5 };
6 int main(void) {
    struct S S = { 'a', 'b', 'c', 'd' };
7
    printf("%d", sizeof(S.S) - strlen(S.S) + S.S[4]);
8     return 0;
9 }
10

 the program outputs 1


 the program outputs 2
 the program outputs 4
 the program outputs 8

Which of the following examples are legal ways of initializing the  arr  array? Select two answers.

int arr[] = {1, 2, 3};

int arr[3] = {1, 2, 3};

int arr{3} = [1, 2, 3];

int arr{3} = {1, 2, 3};

What happens if you try to compile and run this program?

1 #include <stdio.h>
#include <string.h>
2
int main(void) {
3     char s[5] = "ABC";
4  
5     strcat(s + 1, "ABC");
6
    printf("%d", s[0] - s[1]);
7     return 0;
8 }
9

 the program outputs -2


 the program outputs -1
 the program outputs 0
 the program outputs A

What is the value of the following integer literal?


010

 2
 8
 10
 the literal is invalid

What happens if you try to compile and run this program?

1
2 #include <stdio.h>
3 int main(void) {
    int i = 1, j = -1;
4     for(;;) {
5         i *= 2;
6         j++;
7         if(i >= 16)
            break;
8
    }
9     printf("%d",j);
10     return 0;
11 }
12

 the program outputs 0


 the program outputs 1
 the program outputs 2
 the program outputs 3
Which of the following is a correct way of making comments in C?

/* my comment */

*/ my comment /*

# my comment #

<!-- my comment -->

What happens if you try to compile and run this program?

1
2 #include <stdio.h>
3 int main(void) {
4     int i, j, k;
5     i = 1;
    j = 3;
6     if(j)
7         j--;
8     else
9         i++;
10     if(i)
        i--;
11     else
12         j++;
13  
14     k = i + j;
15     printf("%d",k);
    return 0;
16
}
17
18

 the program outputs -1


 the program outputs 0
 the program outputs 1
 the program outputs 2

What is the value of the  var  variable at the end of the following snippet?

1
int var;
2 var = 4;
3 var = var * var;
4 var = var + var;
5  /*
var = var / var;
6 var = var % var;
7   */
8

 0
 16
 32
 64

Which of the following are legal variable names in the C language? Select three answers.

MyVariable

My_Variable

_myVariable

01myvariable

MyV@riable
What happens if you try to compile and run this program?

1
2 #include <stdio.h>
3 #include <string.h>
#include <stdlib.h>
4 struct S {
5     char *S;
6 };
7  
8 int main(void) {
9     struct S *S = (struct S *) malloc(sizeof(struct S));
    S -> S = "123\0""45678";
10     printf("%d", strlen(S -> S + 5) + S -> S[3]);
11     free(S);
12     return 0;
13 }
14

 the program outputs 1


 the program outputs 2
 the program outputs 4
 the program outputs 8

What is the output of the following program?

1
2 #include <stdio.h>
3 void fun(int a, int b)
{
4     printf("%d", b);
5     printf("%d", a);
6 }
7 int main()
{
8
    int arr[] = {1, 2, 3, 4};
9     fun(arr[1], arr[3]);
10     return 0;
11 }
12

 13
 24
 42
 ab

What is the value of the  var  variable after the execution of the following snippet of code:

1 int var;
2 var = -1;
3 var = var + 1;
var = var + var;
4

 the program outputs -1


 the program outputs 0
 the program outputs 1
 the program outputs 2

What happens if you try to compile and run this program?

1
2 #include <stdio.h>
3 int main(void) {
    int i = 3, j = i - 2 * i;
4     switch(i - j) {
5         case  1: j++;
6         case  2: j--;
7         case  0: j++; break;
        default: j = 0;
8
    }
9     printf("%d", ++j);
10     return 0;
11 }
12

 the program outputs 0


 the program outputs 1
 the program outputs 2
 the program outputs 4
Is the following declaration valid?

1 int var, Var;

 Yes
 No

What happens if you try to compile and run this program?

1
#include <stdio.h>
2 int main(void) {
3     int i, t[4];
4  
5     t[3] = 0;
6     for(i = 1; i >= 0; i--)
7         t[i] = t[3] * i;
    printf("%d",t[1]);
8     return 0;
9 }
10

 the program outputs 0


 the program outputs 1
 the program outputs 2
 the program outputs 3

What happens if you try to compile and run this program?

1
#include <stdio.h>
2 int main(void) {
3     int i = -1, j = 1;
4     for(i++; i++; i++)
5         j++;
    printf("%d",i + j);
6
    return 0;
7 }
8

 the program outputs 1


 the program outputs 2
 the program outputs 3
 the program enters an infinite loop and outputs nothing

What is the value of the following integer literal?


0x10

 10
 11
 16
 the literal is invalid

What happens if you try to compile and run this program?

1
2 #include <stdio.h>
3 #include <stdlib.h>
4 struct S {
5     int a;
    struct S *b;
6 };
7 int main(void) {
8     struct S *x = malloc(sizeof(struct S));
9     struct S *y = malloc(sizeof(struct S));
10     x->a = 1;
    x->b = y;
11     y->a = 2;
12     y->b = x;
13     printf("%d",x->b->b->b->a);
14     free(x); free(y);
    return 0;
15
}
16
17

 the program outputs 1


 the program outputs 2
 the program outputs 3
 the program outputs 4
Which of the following are valid floating-point literals? Select two answers.

 -0.1
 .1
 -1
 1

What is the output of the following program?

1
2 #include <stdio.h>
3  
4 int main()
{
5     int arr[5] = {1, 2, 3, 4, 5};
6     arr[1] = 0;
7     arr[3] = 0;
8  
9   for(int i = 0; i < 5; ++i) {
      printf("%d ", arr[i]);
10   }
11   return 0;
12  
13     return 0;
14 }
15

 1
 10305
 00045
 02045

The French language is an example of:

 a programming language
 a machine language
 a natural language
What happens if you try to compile and run this program?

1
2 #include <stdio.h>
struct S {
3     int Var;
4     struct S *Str;
5 };
6 int main(void) {
    struct S S[] = { { 8, NULL }, { 4, &S[0] }, { 2, &S[1] } };
7
    printf("%d", S[2].Str->Str->Var);
8     return 0;
9 }
10

 the program outputs 1


 the program outputs 2
 the program outputs 4
 the program outputs 8

What is the output of the following program?

1
2 #include <stdio.h>
3  
int main () {
4
 
5     int* a, b;
6     b = 1;
7     a = &b;
8     b = 2;
    printf("%d\n", b);
9     printf("%d", *a);
10
 
11    return 0;
12 }
13

 1
1
 1
2
 2
1
 2
2

What happens if you try to compile and run this program?

1
#include <stdio.h>
2 int main(void) {
3     int i = 1, j = 2;
4     for(j > 0; j ; j--)
5         i *= 2;
    printf("%d",i + j);
6     return 0;
7 }
8

 the program outputs 1


 the program outputs 2
 the program outputs 4
 the program enters an infinite loop and outputs nothing

What happens if you try to compile and run this program?

1
2 #include <stdio.h>
int main(void) {
3     int i, j;
4     i = 1; j = 1;
5     while(i > 16) {
6         i += 4;
7         j++;
    }
8     printf("%d",j);
9     return 0;
10 }
11

 the program outputs 0


 the program outputs 1
 the program outputs 4
 the program outputs 5
What happens if you try to compile and run this program?

1
2 #include <stdio.h>
int main(void) {
3     int i = 4, j = 1;
4     while(j > 0) {
5         i /= 2;
6         printf("%d", i);
    }
7     printf("%d",i + j);
8     return 0;
9 }
10

 the program outputs 5


 the program outputs 21
 the program enters an infinite loop and outputs a single line containing an infinite number of 21s
 the program enters an infinite loop and outputs a single line containing 21 followed by an
infinite number of 0s

You might also like