Module 1 Exam Study Guide part 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which C operator is used to dereference a pointer? * & -> .

*

The output file of the pre-processor and compiler are both stored as ___________ files, but the output files of the assembler and linker are both stored as ___________ files.

1. text 2. binary

How many bytes of memory are needed to store the following string (there is a space after the comma). "Hey, Jude" a. 10 b. 9 c. 11 d. 12 e. 13

10 Reasoning: must accommodate for the terminating null character when considering the number of bytes needed to store a string in memory. Whatever the length of the string is... add one to it to get the required number of bytes.

What is the output of the following code? Assume that the address of the variable x is 8 and the address of the variable y is 6. int x = 5; int *y = &x; *y = 1; printf ( "%d", x + *y ); a. 7 b. 2 c. 6 d. 9

2 Reasoning: Changing the value of the address that "y" points to causes that address to change for all variables that have that same memory address.

char **ptr = 65; What would you get by accessing **ptr? a. the character whose ASCII is 65 b. The character stored at address 65 c. The character whose address is stored in memory location 65 d. none of these

The character whose address is stored in memory location 65 Reasoning: pointers hold memory addresses not ASCII characters.

Which of the following statements is TRUE about the following code? int *x = 0; printf ("x = %d", *x); a. The code will cause a segmentation fault b. The output will be x = 0 c. There is not enough info to know the output d. The code will not compile because it has a syntax error

The code will cause a segmentation fault Reasoning: memory address 0 is reserved for the null pointer by the compiler so it will interpret a pointer of address to a NULL pointer. A pointer of 0 means the program failed

What would happen if you try to compile and run the following code in a C function? char str[ ] = "hey jude"; str[3] = '\0'; printf ( "%s", &str[0] ); a. The code would NOT compile, as you cannot modify a char array b. The code would compile, but there would be a segmentation fault c. The code would compile, but it would not produce any output d. The code would compile and produce the output "hey"

The code would compile and produce the output "hey" Reasoning: The code fragment replaces the white space char with the null space char. When read by the compiler, it will terminate and print the output of everything BEFORE the null pointer. So the rest of the string is discarded.

Printing &x will produce what output?

address of x

A pointer is a variable that stores what type of information? a. an address b. an integer c. a parameter d. a data structure

an address Reasoning: pointers are reference variables that point to an address in memory.

Which stage of compilation produces object files as output? a. compiling b. assembling c. linking d. preprocessing

assembling

Which stage(s) of compilation will occur by executing gcc -c code.c (more than one may be correct) a. linking b. assembling c. compiling d. preprocessing

assembling, compiling, and preprocessing Reasoning:

Which component is used to carry word-sized chunks of information? a. I/O controllers b. buses c. program counter (PC) d. registers

buses

Given the declaration: char **argv; what is the type of &argv[0]? a. char b. char * c. char ** d. char ***

char ** Reasoning: argv is initialized as an array of double char pointers so each element in the array also has an address value of char double pointer.

What distinguishes the meaning of bits used to represent data objects? a. source code b. context c. ASCII d. binary

context

Consider the following line of code (assume it is in main() ): double *d = ( double* ) malloc( sizeof ( double ) ); What is the type of d? a. double* b. double c. double** d. none of these

double* Reasoning: d is a pointer and while malloc allocates for a size of a regular double it is type-casted to a double pointer (double*)

Consider the following line of code (assume it is in main() ): double *d = ( double* ) malloc( sizeof ( double ) ); What is the type of &d? a. double b. double* c. double** d. none of these

double** Reasoning: since d is a pointer of type double, its address is also a pointer because pointers are references not literals.

Which of the following provides an abstraction of the actual processor hardware? a. virtual memory b. application program interface c. application binary interface d. instruction set architecture

instruction set architecture Reasoning:

Which of the following describe the "shell" ? (More than one may be correct) a. it is a command-line interpreter b. it prints a prompt then waits for the user to type a command line c. it always has a graphical interface d. it performs commands typed by the user e. it surrounds the application software

it is a command-line interpreter, it prints a prompt then waits for the user to type a command line, and it performs commands typed by the user

Which component of the compilation process combines object files into one executable object program? a. linker b. pre-processor c. assembler d. compiler

linker

Which C function serves the purpose of assigning new memory to a pointer? a. malloc( ) b. strdup( ) c. clone( ) d. free( ) e. allocate( )

malloc( ) Reasoning: malloc( ) stands for memory allocation

Which computer organization component serves as a temporary storage device that holds data while a program is executing? a. CPU b. bus c. I/O device d. memory

memory

Which stage of compilation works with statements like #include <stdio.h> ? a. preprocessing b. assembling c. compiling d. linking

preprocessing

Assume the pointer "ptr" is initialized to "NULL". Which of the following lines will NOT produce a segmentation fault? a. printf ( "%s", *ptr ); b. printf ( "%d", ptr ); c. printf ( "%s", ptr ); d. printf ( "%d", ptr[0] );

printf ( "%d", ptr ); Reasoning: a segmentation fault occurs when a program tries to access memory that it is not allowed to. The other options all tried to manipulate the null pointer in some way that was a misuse of memory

What CPU component consists of word-sized storage units that have unique names? a. PC b. bus interface c. ALU d. register file

register file

Variables that are local to a function are stored in what part of memory? a. stack b. heap c. data d. code

stack Reasoning: the stack is where memory is created and destroyed for function calls at runtime

Consider the following function: // add two numbers and store the result in ans void add_ptr ( int num1 , int num2 , int *ans ) { int sum = num1 + num2; ans = &sum; } int main() { int x = 3, y = 4, z; add_ptr( x , y , &z ); return 0; } Check all the options below that are true AFTER this function is called. a. the value z in main() will be equal to 7. b. the value of sum inside the add_ptr function will be equal to 7. c. the sum of num1 and num2 never make it back to main() d. none of these

the value of sum inside the add_ptr function will be equal to 7. and the sum of num1 and num2 never make it back to main() Reasoning: The values of x and y are passed to the add_ptr function, but because pointers are not passed to the function, that sum is never returned to the main method.

Which of the following is NOT a reason to understand how compilation works? a. you can optimize your program's performance b. you can quickly debug run-time exceptions c. you can resolve link-time errors d. you can avoid buffer overflows and other security vulnerabilities.

you can quickly debug run-time exceptions


संबंधित स्टडी सेट्स

Escalier 3: 3 Le portable perdu vocabulaire

View Set

BIO OCR A LEVEL AS + A2 + PRACTICAL TERMS

View Set

Chapter 44: Digestive and Gastrointestinal Treatment Modalities Required Competency

View Set

Fundamentals of Strategic Decision Making - Exam 2

View Set