C for Everyone: Programming Fundamentals Final Exam (Week 6 Coursera)

¡Supera tus tareas y exámenes ahora con Quizwiz!

In a format string for printf which would you use to print an int?

%d

In ANSI standard C(1989) code - this is what we are teaching- declarations can occur in a for statement as in for(int i; i < 10; i++0 ...

F

Assume the given declarations and fill in the value of the expression . int a = 1, b = 2, c = 3; Expression: a - b * c

-5

Assume the given declarations and fill in the value of the expression . int a = 3, b = 4, c = 0, d = '1'; Expression: a / b > c

0

Assume the given declarations and fill in the value of the expression . int a = 1, b = 2, c = 3; Expression: a++ + --b

2

Assume the given declarations and fill in the value of the expression . int a = 1, b = 2, c = 3; Expression: c / a * b

6

In the following code fragment int a[10] = {1,2,3,4,5,6,7,8,9,10}, i = 6 ; int *p = &a[0]; printf("%d\n", *(p + i)); what gets printed?

7

The expression PI * radius * radius would be used to compute

A circles area

The input function scanf() uses "call by reference" to pass in argument values.

True

If a function's declaration is int foo(void):

The function has no arguments

With the code int foobar(int* n){ *n = *n +1; return *n; } when called int k = 6; printf("foobar(k) = %d,",foobar(&k) ); printf(" k = %d\n", k); what gets printed?

foobar(k) = 7, k = 7

Assume the given declarations and fill in the value of the expression . int a = 1, b = 2, c = 3; Expression: b = a = c

3

Assume the given declarations and fill in the value of the expression . int a = 3, b = 4, c = 0, d = '1'; Expression: a % b

3

Assume the given declarations and fill in the value of the expression . int a = 3, b = 4, c = 0, d = '1'; Expression: c = a++

3

If you declare the array char mystr[10];

None of these

True/ False An if-else statement can always replace an if statement.

True

True/False A while can always be used to replace a for.

True

Who invented the C language?

Dennis Ritchie invented C at Bell Labs

When you compile a correct C program you get a machine executable file such as a.out produced by the gnu compiler gcc.

True

The function mystery is defined as int mystery(int p, int q){ int r; if ((r = p % q) == 0) return q; else return mystery(q, r); } When called with mystery(2, 6) it will return

2

The function mystery is defined as int mystery(int p, int q){ int r; if ((r = p % q) == 0) return q; else return mystery(q, r); } When called with mystery(7, 91) it will return

7

Assume the given declarations and fill in the value of the expression . int a = 3, b = 4, c = 0, d = '1'; Expression: c < b && a > 3

0

Assume the given declarations and fill in the value of the expression . int i = 0, j = 1, k = 2; Expression: !!i

0

Assume the given declarations and fill in the value of the expression . int i = 0, j = 1, k = 2; Expression: i && j

0

Assume the given declarations and fill in the value of the expression . int i = 0, j = 1, k = 2; Expression: i || !k

0

Assume the given declarations and fill in the value of the expression . int a = 3, b = 4, c = 0, d = '1'; Expression: a < b

1

Assume the given declarations and fill in the value of the expression . int a = 3, b = 4, c = 0, d = '1'; Expression: b % a

1

Assume the given declarations and fill in the value of the expression. int i = 0, j = 1, k = 2; Expression: (i && (j = k)) || (k > j)

1

True/False: The declaration char* str = & a[0]; where char a[5] = "abcd"; The value of *str is the char 'a';

True

if p and q are pointers to double and x and y are double which of the following is legal:

y = *q;

A variable declared in a inner block that has the same name as one in the surrounding block causes an error.

F

The following program is suppose to write Hello World onto the screen but it has syntax errors - find and correct. #include <stdio.h> int main(void) { printf(" Hello World\n"); return 0, }

It should be return 0;

The original intent of using register int i; was

It was intended to compile optimized code

The statement printf("HELLO\t\tWORLD\n");

Prints HELLO WORLD followed by a new line

What happens when the return statement has a double expression and the function return type is int?

There is a conversion from double to int

When declaring fact() why not use double fact() so that you do not have integer overflow?

There would be problems with accuracy.

Which is true: 1. #define is a preprocessor command often used to introduce named constants 2. double and goto are keywords declaring types. 3. return (0); is normally the last statement in main() 4. The file stdio.h is where the compiler finds scanf().

1, 3, 4

In the following code fragment what gets printed? int data[5] = {0 ,1, 2, 3, 4}, sum = 0 , i; for (i = 0; i < 5 ; i++) sum = sum + data[i]; printf("%d\n", sum);

10

The code i = -10; while ( i < 0) { ... do something ; i--; } Displays a common error

its an infinite loop

True/False - Factorial can only be computed recursively.

F

True/False mergesort is less efficient than bubblesort for very large sorting problems.

F


Conjuntos de estudio relacionados

BIO 109 - CHAPTER 36: Population Ecology

View Set

Ch.10 - Commercial Auto Coverage

View Set

Essentials of Human Anatomy and Physiology(11) Activity Lab 6

View Set