Midterm Flashcards
What is the value of i and j?
i = 2; j = 1;
while (( i>-5) || (j - - > 0){ if ( (j%2) && (i - - % 3)) printf ("%d", j); else printf ("%d\n", i); } return 0; }
2 > -5 = true, so move to next step
j (1)%2 = true & 2 - - %3 = true
then starts over
1 > -5 = true
j (1)%2 = true & 2 - - %3 = true
-keeps working remainder through until remainder is false (0) and then prints.
Answer:
11 -1
11 -4
1 -5
How to write a program to clear the buffer
while (get char ( ) != ‘\n’)
What does ? : mean?
? = if \: = else
x = 0;
y (x>0) ? 10 : -10
answer 10
What is x?
x = 10 y = 0
y > 10) && (x - - >10
answer 10
What is x?
x = 10 y = 10
y > 10) || (x - - >10
answer 10
How to check if a char variable is an uppdercase letter?
((ch >= ‘A’) && (ch
How many times will this print? int count = 0; do { printf (Welcome) } while ++count
answer 10
How many iterations (executions) in the loop?
int;
for (i = 1; i
answer n
int even = 0;
printf (“%d, even ? “true” : “false”)
answer false
How many times will this print? int count = 0; do { printf ("Welcome"); } while (count++
answer 10
Which code is preferred? code 1: if (number%2 = = 0) even = 1; else even = 0;
code 2: even = (number %2 = = 0) ? 1:0
code 3: even = number % 2 = = 0);
answer = all three are correct but code 3 is preferred.
How to clear the buffer?
fflush (stdin)
How to deallocate memory in a dynamic array?
free ( (void *) d_ptr );
How can memory in an array be allocated?
malloc ( )