CLA - C Certified Associate Programmer Questions and Answers
Assume that ints are 32-bit wide.
What happens if you try to compile and run this program?
#include
typedef union {
int i;
int j;
int k;
} uni;
int main (int argc, char *argv[]) {
uni s;
s.i = 3;
s.j = 2;
s.k = 1;
printf("%d",s.k * (s.i - s.j));
return 0;
}
Choose the right answer:
What happens if you try to compile and run this program?
#include
#include
int main (int argc, char *argv[]) {
double x = 1234567890.0;
printf ("%f",x);
return 0;
}
Choose the most precise answer:
What happens if you try to compile and run this program?
#include
int main(int argc, char *argv[]) {
int i = 10 - 2 / 5 * 10 / 2 - 1;
printf("%d",i);
return 0;
}
Choose the right answer:
What happens if you try to compile and run this program?
#include
#include
int main (int argc, char *argv[]) {
int a = 0, b = 1, c;
c = a++ && b++;
printf("%d",b);
return 0;
}
Choose the right answer:
What happens if you try to compile and run this program?
#include
int main (int argc, char *argv[]) {
int i = 2;
int d= i << 2;
d /= 2;
printf ("%d", d) ;
return 0;
}
Choose the right answer:
What happens if you try to compile and run this program?
#include
struct s {
int i;
};
void fun(struct S st) {
st.i --;
int main (void) {
int k;
struct $ str1 = { 2 };
fun (str1) ;
k =str1.i;
printf("%d", k);
return 0;
}
-
Choose the correct answer:
What happens if you try to compile and run this program?
#include
int main (int argc, char *argv[]) {
int main, Main, mAIN = 1;
Main = main = mAIN += 1;
printf ("%d", MaIn) ;
return 0;
}
Choose the right answer:
Assume that we can open a file called "file1".
What happens when you try to compile and run the following program?
#include
int main (void) {
FILE *f;
int i;
f = fopen("file1","wb");
fputs("545454",f);
fclose (f);
f = fopen("file1","rt");
fscanf(f,"%d ", &i);
fclose (f) ;
printf("%d",i);
return 0;
}
Choose the right answer:
Assume that ints are 32-bit wide.
What happens if you try to compile and run this program?
#include
typedef struct
int i;
int j;
int k;
} str;
int main (int argc, char *argv[]) {
str s = { 7, 7, 7 };
printf ("%d", sizeof (s.s));
return 0;
}
Choose the right answer:
What happens if you try to compile and run this program?
#include
int main (int argc, char *argv[]) {
char i = 20 + 020 + 0x20;
printf("%d",i);
return 0;
}
Choose the right answer:
What happens if you try to compile and run this program?
#include
int main (int argc, char *argv[]) {
char *t = "abcdefgh";
char *p = t + 2;
int i;
p++;
p++;
printf("%d ", p[2] - p[-1]);
return 0;
}
Choose the right answer:
-
What happens if you try to compile and run this program?
#include
int *f();
int main (int argc, char *argv[]) {
int *p;
p = f();
printf("%d",*p);
return 0;
}
int *f() {
static v = 1;
return &v;
}
Choose the right answer: