Midterm Flashcards

1
Q

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;
}
A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to write a program to clear the buffer

A

while (get char ( ) != ‘\n’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does ? : mean?

A
? = if
\: = else
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

x = 0;

y (x>0) ? 10 : -10

A

answer 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is x?

x = 10 y = 0
y > 10) && (x - - >10

A

answer 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is x?

x = 10 y = 10
y > 10) || (x - - >10

A

answer 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to check if a char variable is an uppdercase letter?

A

((ch >= ‘A’) && (ch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
How many times will this print?
int count = 0;
do {
  printf (Welcome)
    }
while ++count
A

answer 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How many iterations (executions) in the loop?
int;
for (i = 1; i

A

answer n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

int even = 0;

printf (“%d, even ? “true” : “false”)

A

answer false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
How many times will this print?
int count = 0;
do
{
printf ("Welcome");
} while (count++
A

answer 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
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);

A

answer = all three are correct but code 3 is preferred.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to clear the buffer?

A

fflush (stdin)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to deallocate memory in a dynamic array?

A

free ( (void *) d_ptr );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can memory in an array be allocated?

A

malloc ( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an address operator? (array)

A

& gives the address of a variable

17
Q

What is the dereferencing operator? (array)

A
  • used with an address, gives the contents of that address
18
Q

What is the sizeof ( ) operator used for in an array?

A

Used with an array to return the number of bytes in that array

19
Q

How to deallocate memory in a dynamic array?

A

free ( (void *) d_ptr ); or free ( )

20
Q

What can be used as a function declaration of an array?

A

funct ( int *array)

funct ( int array [ ] )

21
Q

What can be used as a function call for an array?

A

int array [ 50]

funct (array);

22
Q

The name of an array without any brackets will give the address of which cell?

A

The first cell

23
Q

In an array, what does setting a pointer to NULL do?

A

Indicates that it doesn’t point anywhere

24
Q

How many bytes does a floating point value use in array?

A

4 bytes. An 8 element array will use 32 bytes

25
Q

What type of values can and cannot be used with a switch statement?

A
Cannot = float or double
Can = integer or character