CLA-11-03 Exam Question 1
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
char *p = "World";
int i = 2;
switch (p[i]) {
case 'W' :i++; break ;
case 'o' :i += 2; break ;
case 'r' :i += 3; break ;
case '1' :i += 4; break ;
case 'd' :i += 5; break ;
default :i += 4;
}
printf("%d", i);
return 0;
}
-
Choose the right answer:
#include <stdio.h>
int main (int argc, char *argv[]) {
char *p = "World";
int i = 2;
switch (p[i]) {
case 'W' :i++; break ;
case 'o' :i += 2; break ;
case 'r' :i += 3; break ;
case '1' :i += 4; break ;
case 'd' :i += 5; break ;
default :i += 4;
}
printf("%d", i);
return 0;
}
-
Choose the right answer:
CLA-11-03 Exam Question 2
What happens if you try to compile and run this program?
#define ALPHA 0
#define BETA ALPHA-1
#define GAMMA 1
#define dELTA ALPHA-BETA-GAMMA
#include <stdio.h>
int main(int argc, char *argv[]) {
printf ("%d", DELTA);
return 0;
Choose the right answer:
#define ALPHA 0
#define BETA ALPHA-1
#define GAMMA 1
#define dELTA ALPHA-BETA-GAMMA
#include <stdio.h>
int main(int argc, char *argv[]) {
printf ("%d", DELTA);
return 0;
Choose the right answer:
CLA-11-03 Exam Question 3
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
int i = 1;
for( ;; i/=2)
if(i)
break ;
printf("%d",i);
return 0;
}
Choose the right answer:
The program executes an infinite loop
#include <stdio.h>
int main (int argc, char *argv[]) {
int i = 1;
for( ;; i/=2)
if(i)
break ;
printf("%d",i);
return 0;
}
Choose the right answer:
The program executes an infinite loop
CLA-11-03 Exam Question 4
Assume that ints and floats are 32-bit wide.
What happens if you try to compile and run this program?
#include <stdio.h>
union uni {
float f, g;
int i, j;
};
int main (int argc, char *argv[]) {
union uni u;
printf ("%ld", sizeof (u) ) ;
return 0;
}
Choose the right answer:
What happens if you try to compile and run this program?
#include <stdio.h>
union uni {
float f, g;
int i, j;
};
int main (int argc, char *argv[]) {
union uni u;
printf ("%ld", sizeof (u) ) ;
return 0;
}
Choose the right answer:
CLA-11-03 Exam Question 5
What happens when you compile and run the following program?
#include <stdio.h>
int fun (void) {
static int i = 1;
i += 2;
return i;
}
int main (void) {
int k, 1;
k = fun ();
1 = fun () ;
printf ("%d", 1 - k);
return 0;
}
Choose the right answer:
#include <stdio.h>
int fun (void) {
static int i = 1;
i += 2;
return i;
}
int main (void) {
int k, 1;
k = fun ();
1 = fun () ;
printf ("%d", 1 - k);
return 0;
}
Choose the right answer: