CSE 240 Quiz 3 C Programming

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

C Programming What is the output of the code below? ----------------------------------------------------------------------------- #include <stdio.h> int main() { int a[5] = { 3, 1, 5, 20, 25 }; int i, j, m; i = *(a + 1) - 1; j = a[1] + 1; m = a[j] + a[i]; printf("%d. %d, %d", i, j, m); return 0; } ----------------------------------------------------------------------------- A. 0, 2, 6 B. 0, 2, 5 C. 0, 2, 8 D. 0, 1, 6

0, 2, 8

A name given to a storage location that stores an address

Pointer

C Programming Which of the following are NOT primitive data types in C? ----------------------------------------------------------------------------- A. int B. bool C. char D. String E. double F. float G. short H. long

bool String short long

C Programming Given the following struct: struct contact { char name[32]; int phone; char email[32]; }; Which code can be used to create a contact and store data? ----------------------------------------------------------------------------- A. struct contact x; scanf("%s", x.name); scanf("%d", &x.phone); scanf("%s", x.email); ----------------------------------------------------------------------------- B. struct contact x; scanf("%s", &x.name); scanf("%d", &x.name); scanf("%s", &x.email); ----------------------------------------------------------------------------- C. struct contact x; scanf("%s", x.name); scanf("%d", x.phone); scanf("%s", x.email); ----------------------------------------------------------------------------- D. struct contact x; scanf("%s", &x.name); scanf("%d", x.phone); scanf("%s", &x.email);

struct contact x; scanf("%s", x.name); scanf("%d", &x.phone); scanf("%s", x.email);

C Programming %c

printing format for char values

C Programming %f

printing format for float values

C Programming %d

printing format for integer values

C Programming %p

printing format for memory addresses (pointer and stored values).

C Programming %s

printing format for string values

C programming Which of the following programs are correct in C? ----------------------------------------------------------------------------- A. typedef int booOoolean; typedef char FlagType; int main() { booOoolean x = 0; int counter; FlagType xx = 'A'; // comment } ----------------------------------------------------------------------------- B. typedef enum { red, amber, green} traffic_light; main() { traffic_light x = red; while(1) switch (x) { case amber: x = red; printf("R"); break; case red: x = green; printf("G"); break; case green: x = amber; printf("A"); break; } } ----------------------------------------------------------------------------- C. typefed enum {false, true} booOoolean; typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} days; int main() { booOoolean a = false; int counter; days x = Mon, Fri; while (x != y) x++; }

typedef int booOoolean; typedef char FlagType; int main() { booOoolean x = 0; int counter; FlagType xx = 'A'; // comment } -------------------------------------------------------------- typedef enum { red, amber, green} traffic_light; main() { traffic_light x = red; while(1) switch (x) { case amber: x = red; printf("R"); break; case red: x = green; printf("G"); break; case green: x = amber; printf("A"); break; } } -------------------------------------------------------------- typefed enum {false, true} booOoolean; typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} days; int main() { booOoolean a = false; int counter; days x = Mon, Fri; while (x != y) x++; }

C Programming Which of the following are correct declarations of the main() method (i.e., the entry point of the program)? ----------------------------------------------------------------------------- A. void main(int argc, char* argv[]){ } ----------------------------------------------------------------------------- B. int main(int argc, char* argv[]) { return 0; } ----------------------------------------------------------------------------- C. int main() { return 0; } ----------------------------------------------------------------------------- D. void main() { } public static void main(string[] argv) { } ----------------------------------------------------------------------------- E. main() { return 0; }

void main(int argc, char* argv[]){ } -------------------------------------------------------------- int main(int argc, char* argv[]) { return 0; } -------------------------------------------------------------- int main() { return 0; } -------------------------------------------------------------- main() { return 0; }

A name given to a storage location

Variable

C Programming Considering the following code: struct emp { int id; char* name; }; struct emp john; Which of the following lines are correct? ----------------------------------------------------------------------------- A. int a = 1; char b[] = "John Doe"; john.id = a; john.name = b; printf("%d, %s", john.id, john.name); ----------------------------------------------------------------------------- B. int a = 1; char b[] = "John Doe"; john[0].id = a; john[0].name = b; printf("%d, %s", john[0).id, john[0].name); ----------------------------------------------------------------------------- C. int a = 1; char b[] = "John Doe"; emp.id = a; emp.name = b; printf("%d, %s", emp.id, emp, name); ----------------------------------------------------------------------------- D. int a = 1; char b[] = "John Doe"; john.id = b; john.name = a; printf("%d, %s", john.id, john.name);

int a = 1; char b[] = "John Doe"; john.id = a; john.name = b; printf("%d, %s", john.id, john.name);

C Programming Which code is equivalent to this code in Java int x = 5; float y = 10.3f; System.out.println("hello " + x + " bye " + y); ----------------------------------------------------------------------------- A. int x = 5; float y = 10.3; printf("hello %d bye %f", x, y); ----------------------------------------------------------------------------- B. int x = 5; float y = 10.3f; printf("hello %i bye %f", x, y); ----------------------------------------------------------------------------- C. int* x = 5; float* y = 10.3; printf("hello %p bye %p", x, y); ----------------------------------------------------------------------------- D. int x = 5; float y = 10.3; printf("hello %d bye %f", &x, &y);

int x = 5; float y = 10.3; printf("hello %d bye %f", x, y);

Fixed value that the program may not alter during its execution

Constant

A classification that specifies which type of value a variable has and what type of mathematical relational, or logical operations can be applied to it.

Data Type

C Programming What is printed on screen after running this program? #include <stdio.h> int main() { int i = 0; char a[] = "H2o2"; while (a[i] != '\0') { *(a + 1) = *(a + i) + 2; i++ } char* q = a; q[2] = '#'; printf("%s", a); return 0; } ----------------------------------------------------------------------------- A. I3p2 ----------------------------------------------------------------------------- B. I3#3 ----------------------------------------------------------------------------- C. H4#2 ----------------------------------------------------------------------------- D. H3#2

H4#2

C Programming What is the output of the following program? #include <stdio.h> typedef enum week {Mon, Tue, Wed, Thur, Fri, Sat, Sun} WEEK; int main() { WEEK day; day = Wed; printf("%d", day); return 0; }

2

C Programming What does the below program print on the screen? #include <stdio.h> int main() { int i = 3, * j, k; j = &i; printf("%d \n", i**j*i-*j); return 0; }

24

C Programming What is the output of the below code? #include <stdio.h> int fun(int n) { if (n == 4) return n; else return 2 * fun(n + 1); } int main() { printf("%d", fun(3)); return 0; }

8

C Programming In a C Program, which of the following is true? ----------------------------------------------------------------------------- A. C allows empty parameters or two parameters for main ----------------------------------------------------------------------------- B. C allows only one parameter for main ----------------------------------------------------------------------------- C. C allows more than two parameters for main ----------------------------------------------------------------------------- D. C allows one parameter or two parameters for main

C allows empty parameters or two parameters for main

C Programming In C, when you pass an array as a parameter to a function, what is actually passed? ----------------------------------------------------------------------------- A. The value of the first element in the array ----------------------------------------------------------------------------- B. The address of the first element in the array ----------------------------------------------------------------------------- C. All the values in array ----------------------------------------------------------------------------- D. An array cannot be passed as a parameter to a function

The address of the first element in the array

C Programming The following code is correct and prints "Hello" if (2 + 2 + 2 + 2) if (1) printf("Hello"); ----------------------------------------------------------------------------- True False

True

C Programming char, unsigned char, signed char, and int are all numeric (integer) types in C programming ----------------------------------------------------------------------------- True False

True

C Programming What is printed by the following code? #include <stdio.h> int i = 10; int bar(int m, int* n) { printf("i = %d k = %d l = %d \n", i, m, *n); } int foo(int k, int* l) { printf("i = %d k = %d l = %d \n", i, k, *l); } int main() { int j = 15; foo(j, &i); printf("i = %d j = %d \n", i, j); return 0; } ----------------------------------------------------------------------------- A. i = 10 k = 15 l = 10 I = 10 k = 3 l = 4 I = 10 j = 15 ----------------------------------------------------------------------------- B. i = 4 k = 3 l = 4 I = 4 j = 15 ----------------------------------------------------------------------------- C. i = 10 k = 15 l = 10 I = 4 k = 3 l = 4 i = 4 j = 15 ----------------------------------------------------------------------------- D. i = 10 k = 15 l = 10 I = 10 k = 3 l = 10 I = 10 j = 15

i = 10 k = 15 l = 10 I = 4 k = 3 l = 4 i = 4 j = 15

C Programming What is printed by the following code? ----------------------------------------------------------------------------- #include <stdio.h> int foo(int* n) { *n = 30; } int main() { int i = 15; foo(&i); printf("i = %d \n", i); i = 10; foo(&i); printf("i = %d \n", i); return 0; } ----------------------------------------------------------------------------- A. i = 10 I = 10 ----------------------------------------------------------------------------- B. i = 30 I = 30 ----------------------------------------------------------------------------- C. i = 30 I = 30 ----------------------------------------------------------------------------- D. i = 15 i = 15

i = 30 i = 30


Conjuntos de estudio relacionados

Climate Change and Ozone- AP Review questions

View Set

RN Pediatric Nursing Online Practice 2023 B

View Set

WH MULTIPLE CHOICE QUESTIONS: SPRING 2017

View Set

LPN practice questions for Crissy-Topic one: Fundamentals

View Set

Basic Insurance Concepts and Principles, Contract Law, Life Insurance - Basics, Type of Life Policies, Individual Life Insurance Contract - Provisions and Options, Life Policy Riders, Annuities, Life Insurance and Annuities - Policy Replacement and C...

View Set

CH 31 LISTENING QUIZ: Mozart: Eine kleine Nachtmusik (A Little Night Music), K. 525, I and III LG 21

View Set

Investment Companies: Variable Annuities (UITs)

View Set