Module 2 Quiz

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Converting an integer value to 5 to a float number 5.0 takes A. At least one important machine instruction to perform conversion between data binary formats. B. Very little work the type labels are the only thing that changes. C. No work, the binary values are identical. D. A tonw ork since it must be converted to several intermediate representations and then finally to the target type.

A. At least one important machine instruction to perform conversion between data binary formats. The machine has to reserve more memory to convert int to float.

Which of the following languages is most likely to report a compilation error for the following snippet of code? int i=3; double n,j=3.0; n=i+j; A. Java B. VSL C. C D. C++

A. Java B C and D are wrong because those languages are weakly typed, meaning you can do things like multiply an int times a float and the language will handle type casting the into to float automatically for you. Java does not allow this behavior because it is strongly typed.

In a given programming and exectuion envronment, a variable declaration in C binds a name to a memory location. What else are also determined in delcaration? Select all that apply. A. Variable type. B. Variable scope. C. The time period that the variable will be in a register of the computer. D. Variable size (number of bytes).

A. Variable type. B. Variable scope. C. Variable size (number of bytes). The time period part might refer to automatic garbage collection, which C does not have.

A variable declaration can involve the following attributes: Select all that apply. A. type B. macro C. address D. scope

A. type D. scope address is determined at runtime by the operating system, not by you. a macro just maps a string of characters to literal pieces of code, when compiled the compiler replaces that character with the mapped code. Macros are not variables.

Implicit Type conversion is commonly reffered to as? A. Casting B. Coercion C. Typing D. Paradigm

B. Coercion

Which of the following statements are correct if a language is strongly typed? Select all that apply. A. Type is not known at compilation time. B. Each name in a program has a single type associated with it. C. Type errors are always reported. D. The variable size can be deteremined at execution time.

B. Each name in a program has a single type associated with it. C. Type errors are always reported. A is wrong because strongly typed languages have to delcare each variables type in the code. D is wrong because declarying the variables type (see A) also declares the size of the variable.

The forward delcaration of a function requires: Select all that apply. A. Function implementation. B. Function name. C. Parameter types. D. Return type. E. Initial address of the function code.

B. Function name. C. Parameter types. D. Return type. void some_func(int param_a, int param_b) {}; void is return type, in this case none. some_func is the name of the function. int param_a and int param_b are the two parameter types.

In C++, what function can be used for inputting a string containing spaces? A. scanf("%s", &str); B. cin.getline(...); C. cin >> str; D. scanf.getline(...);

B. cin.getline(...); & means "address of" Note that %s, %d, %f are called Format tags. s for string, d for integer (digit), f for float, c for char.

In the memory hierarchy of a computer system, which type of memory is the fastest one? A. Secondary storage B. Cache C. Registers D. Main memory

C. Registers Registers >>> Cache >> Main Memory > Secondary Storage

Given the C declaration: char s1[4], s2[] = "hello"; if a string copy function strcpy(s1, s2) is executed, what will happen? A. The result s1 will contain the string "hell", and nothing else happens. B. A run time error will occur. C. The result s1 will contain the string "hell", and the following two byte locations will contain 'o' and '\0'. D. The result s1 will contain the string "hel'\0'"

C. The result s1 will contain the string "hell", and the following two byte locations will contain 'o' and '\0'. Don't get confused by D. This is a straightforward question, no tricks here.

Which of the following C assignments statements will NOT cause a compilation error? Assume the array has been declared as: char a[5]; A. a = "h"; B. a[] = {'h', 'i'}; C. a[0] = 'h'; D. a = "hi";

C. a[0] = 'h'; A and D are wrong because they are trying to assign non-char values to a char array. B is wrong because a[] is already declared, you can only assign values to a[] like that on declaration.

Assume this is a 32-bit environment, given a declaration: int a[10]; What is the size (in bytes) of the entire array? A. 4 B. 10 C. 80 D. 40

D. 40 32-bit is 4 bytes (8 bits * 4) so the default memory size (word) is 32 bits. An array of size 10 reserves 10 memory sizes of 32 bits which equals 320 bits or 40 bytes.

Where is the main() function located in a C++ program? A. In the Main class. B. In all classes. C. In any one class. D. outside any class.

D. outside any class.. Note that you can only have one main function and it cannot be in a class.

In the C-Style input function scanf("%d", &i), what does the character '&' mean? A. scanf takes multiple variables as its parameters. B. scanf takes an integer type variable as its parameter. C. scanf takes the value of an variable as its parameter. D. scanf takes the address of an variable as its parameter.

D. scanf takes the address of an variable as its parameter. & means "address of" Note that %s, %d, %f are called Format tags. s for string, d for integer (digit), f for float, c for char.

Assume a variable is declared in a block of code within a pair of curly braces. The scope of the variable A. starts from its declaration point and extends to the end of the entire program. B. covers the entire block, including the code before the declaration point. C. covers the entire program, including the code in the other blocks. D. starts from its declaration point and extends to the end of the block.

D. starts from its declaration point and extends to the end of the block. Not all languages have curly braces but this is how it behaves for the majority that do. This question really should declare a language.


Set pelajaran terkait

Unit 1 - Introduction to Entrepreneurship

View Set

NSCA CSCS chapter 13: warm up and stretching

View Set

Atomic Models and Properties of Atoms

View Set

Environmental Science Final - Study Guide

View Set

Chapter 12: Request for Comments

View Set

Chapter 46: Assessment and Management of Patients with Diabetes

View Set