answers guaranteed pass
C - correct answers C
Explain the difference between %d and %4d placeholders when printing - correct answers %4d reserves
4 spaces and right aligns the text, e.g
4285
6
but %d would just be centered
write the commands to read a string from input and print it out. Assume a macro is define with max size
SZ - correct answers char s[SZ];
printf("Enter a string with max size %d: ", SZ);
fgets(s, SZ, stdin);
s[strlen(s) - 1] = '\0';
printf("You entered: %s \n", s);
Write the "cookbook" steps to reading/writing from a file - correct answers declare file pointers:
FILE* in;
FILE* out;
initialize pointers:
in=fopen("filename", "r");
out=fopen("filename", "w");
actions:
,fscanf(in, "placeholder", &variable);
fprintf(out, "placeholder", variable);
close files:
fclose(in);
fclose(out);
write the general syntax for a switch statement - correct answers switch (variable) {
case (cond1):
action1;
break;
case (cond2):
case (cond3):
action2;
break;
}
fill in the blanks:
void swap (int *a, int *b) {
int temp;
temp=____; // set to variable pointed to by a
____ = ____; // set variable pointed to by a to the one pointed to by b
____ = temp; // set the variable pointed to by b
}
int main() {
int a=5, b=7;
, swap( ____, ____); // a is now 7, b is now 5
return 0;
} - correct answers *a
*a = *b
*b
swap(&a, &b)
write out the general format for a makefile - correct answers targetfile : dependenciesfiles
action (gcc ...)
targetfile2 : dependeciesfiles2
action
... and so on
the executable show_face depends on object files show_face.o and face.o
show_face.o depends on the source file show_face.c
face.o depends on the source file face.c
write the makefile - correct answers show_face : show_face.o face.o
gcc show_face.o face.o -o show_face
show_face.o : show_face.c
gcc -c show_face.c
face.o : face.c
gcc -c face.c
clean:
rm *.o