Quiz C1-1
Submit your answers via this Google Form
Question 1
This program compiles, but does not work as expected. Select the correct replacement for a matching line of code so that it prints out “equal”.
#include <stdio.h>
int main(){
int a = 10000000;
short b = 10000000;
if( a == b){
printf("equal");
}else{
printf("not equal");
}
}
Question 2
What is the output of this program
#include <stdio.h>
int main() {
unsigned char a = -1; //this is werid, right?
int b = 1;
if (a < b){
printf("Smaller");
}else if( ~(a) < b){ //note that ~ compliments all the bits of a
//flipping 1's to 0's and 0's to 1's
printf("Even Smaller");
}else if(sizeof(a) == sizeof(b)){
printf("Same size");
}
}
Question 3
What is the output of this program
#include <stdio.h>
int main(){
int a = 10;
int b = a++;
int c = ++a;
a = --c;
b = c--;
if( --a == c){
printf("Hello");
}else if(a == b){
printf("world");
}else{
printf("!");
}
}
Question 4
What is the output of this program
#include <stdio.h>
int main(){
int a = 100;
int b = 0;
if((a & b) | b){
printf("true\n");
}else{
printf("false\n");
}
int large = 100;
int small = 50;
if( large >> 1 == small){
printf("Same\n");
}else{
printf("Different\n");
}
}