Quiz
C Programming
Erstelle ein kostenloses Konto, um dieses Quiz zu beenden
Speichere deinen Fortschritt und sieh dir dein Endergebnis an.
oder mit deiner E-Mail registrieren
Schon ein Konto? Anmelden
Fragen in diesem Quiz (76)
1Object files can only have one function per file.
- ARichtig
- BFalsch
2To create a relocatable object library archive from a group of object files, enter the command:
- Alink library file.a object file(s)
- Bar ras libraryfile.a objectfile(s)
- Cranlib library file.a objectfile(s)
- Dzip -r library file.a objectfile(s)
3You should put code you expect to reuse in other programs into a header file.
- ARichtig
- BFalsch
4Dynamically linked object files have the extension .dll in Linux.
- ARichtig
- BFalsch
5If you include code in a header file, it will:
- Abe copied redundantly in every object file created from source that includes the header.
- BAll are correct.
- Ccause a compile error because code, other than declarations, cannot be in a header file.
- Dcreate more compact code because it will compile directly with the source instead of being linked from a library.
6The GCC command line parameter '-c' tells the compiler to:
- Acompile only, without linking any code.
- Buse C syntax as opposed to C# or C++ syntax.
- Ccopy the source file into the object file.
- Dcompress the code output.
7Function declarations, global variable declarations, and #define directives are good to include in a library's header file because:
- AAll are correct.
- BThey provide an interface to the library's functions and data
- CThey prevent you from having to expose private code or write 'getters' and 'setters' for the library code.
- DThey can then be used by any code that includes the header file.
8The directive #define PI 3.1415
- Atells the compiler to make the variable PI equal to 3.1415
- Btells the compiler to alter all instances of PI in the object code to 3.1415
- Ctells the compiler to substitute the float number 3.1415 in the source wherever it encounters the string "PI".
- Dtells the compiler to substitute the string "3.1415" in the source wherever it encounters the string "PI".
9If a library file containing 10 functions is statically linked at compile time instead of dynamically linked at runtime:
- Athe statement makes no sense because linking only occurs at compile time.
- Bthe executable will be smaller but the space used at runtime will be the same.
- Cit can share the library functions with other programs, saving space.
- Dthe statement makes no sense because linking only occurs at runtime.
10#include "mycode.h" directs the compiler to search for mycode.h in the current directory first. Depending on implementation, it may also search subdirectories of the current directory and the systems include path.
- ARichtig
- BFalsch
11To compile relocatable code, use the gcc flag -fPIC.
- ARichtig
- BFalsch
12To prevent a header file mycode.h from being included more than once:
- Aheader files should never include other header files.
- B-Imycode.h should be added to the gcc compiler flags.
- C#ifndef __mycode_h__
#define __mycode_h__
#include "mycode.h"
#endif
should be included in the source file - D#ifndef __mycode_h__
#define __mycode_h__
... code goes here
#endif
should be included in the header file
13Declarations:
- Aneed not include any initialization.
- Bmust come before declared item can be used.
- CAll are correct.
- Dcan go anywhere in a source or header file (except conditional expressions)
14To add a table of relocatable object modules to an archive, use the 'ranlib' utility in linux.
- ARichtig
- BFalsch
15To lump a set of object files together, use the 'ar' (archive) command. The result is a linkable library.
- ARichtig
- BFalsch
16The gcc compiler flag -l followed by a path specifies an additional path for the compiler to search for include files.
- ARichtig
- BFalsch
17Constants are usually defined in all capitals using a define directive so they will stand out.
- ARichtig
- BFalsch
18The #include directive tells the compiler to insert the contents of the specified file into the file that has the directive at the location where the directive is found.
- ARichtig
- BFalsch
19Object files consist of the source code for the function(s) they hold.
- ARichtig
- BFalsch
20#include <mycode.h> directs the compiler to search for mycode.h in the current directory first, then in the system's include path.
- ARichtig
- BFalsch
21int *numPtr;
int num = 100;
numPtr = num;- Astores the address of num into the location pointed at by numPtr
- Bcauses numPtr to point to num.
- Cfails because it tries to point numPtr to the address 100.
- Dfails because numPtr is never initialized.
22You can do math on a pointer but you can't store the result back into the pointer variable.
- ARichtig
- BFalsch
23unsigned long *varname declares varname to be an unsigned long that is used as a pointer.
- ARichtig
- BFalsch
24typedef struct mystruct{ char *name;
char *address; } mystruct;
Adding the structure name before the structure itself means you can use the structure before it was declared.- ARichtig
- BFalsch
25struct mystruct{ char *name;
char *address; );
struct mystruct *mycontact = malloc(sizeof(struct mystruct));
*(mycontact).name = "Charles";
When the above code executes,- Ait stores the string "Charles" in the variable name inside mycontact.
- Bmycontact contains a pointer called name that points to a string, "Charles," stored somewhere on the heap.
- Cit fails because the last line should have been *(mystruct).mycontact.name = "Charles";
- Dit fails because name did not specify a size and no memory for it was allocated.
26&varname can be read as 'address of varname'.
- ARichtig
- BFalsch
27struct mystruct{ char *name;
char *address; };
struct mystruct *mycontact = malloc(sizeof(struct mystruct));
When the above code executes, it- Acreates a variable called mycontact that points to a structure that contains NULL pointers to name and address.
- Bfails because malloc does not know how big the name or address fields are.
- Ccreates a variable called mycontact that contains a name and an address.
- Dcreates a variable called mycontact that points a variable called mystruct.
28int *varptr[] = { 1, 2, 3, 4, 5 );
int x = *(varptr + 2);
The above code sets x to 3.- ARichtig
- BFalsch
29int *numPtr;
int num = 100;
numPtr = #- Acauses numPtr to point to num.
- Bfails because it tries to point numPtr to address 100.
- Cstores 100 in the address pointed to by numPtr.
- Dfails because numPtr is never initialized.
30Assume that pointers are 4 bytes, integers are 2 bytes, characters are 1 byte, and float values take up 4 bytes.
typedef struct { char *name;
char *ID[8];
int rank;
float scores[];
} gradesRecord;
gradesRecord *grades = malloc(sizeof(gradesRecord);
How many bytes were allocated by the malloc function?- ACan't allocate without first allocating name
- B22
- CCan't tell because no dimension was given for scores array.
- D14
31typedef struct mystruct{ char *name;
char *address; };
Adding typedef to the above declaration means I can now declare "mystruct mycontact" instead of "struct mystruct mycontact".- ARichtig
- BFalsch
32struct mystruct{ char *name;
char *address; };
struct mystruct *mycontact = malloc(sizeof(struct mystruct));
mycontact->name = "Charles";
When the above code executes,- Amycontact contains a pointer called name that now points to the string "Charles" stored somewhere in the heap.
- Bit fails because you can't store a string literal into a pointer.
- Cit fails because there was no malloc for name to create space for the string.
- Dit fails because the last line should read &mycontact->name = "Charles";
33struct mystruct{ char *name;
char *address; };
struct mystruct *mycontact = malloc(sizeof(struct mystruct));
char* tempptr = &(mycontact->name);
*tempptr = "Charles";
When the above code executes, it- Agets the address of mycontact and stores the string "Charles" there.
- Bfails because we tried to store a string, "Charles", inside a pointer, tempptr.
- Cgets the address of name inside mycontact and then sets its value to point to the string "Charles" stored somewhere on the heap.
- Dgets the address pointed to by name inside mycontact and stores the string "Charles" at that location.
34unsigned long *varname declares varname to be a pointer to an unsigned long integer.
- ARichtig
- BFalsch
35int varptr[] = { 1, 2, 3, 4, 5 };
int x = varptr;
The above code sets x to 1.- ARichtig
- BFalsch
36int *numPtr;
int num = 100;
*numPtr = num;- Afails because numPtr has not been initialized.
- Bstores 100 in the location numPtr points to.
- Cpoints numPtr to num.
- Dfails because it tries to point numPtr to address 100.
37typedef struct { char *name;
char *address; } mystruct;
The above typedef declaration means I can now declare "mystruct mycontact" instead of "struct mystruct mycontact".- ARichtig
- BFalsch
38int varptr[] = { 1, 2, 3, 4, 5 };
int x = *varptr;
The above code sets x to 1.- ARichtig
- BFalsch
39The elements in a struct can be any type except a pointer.
- ARichtig
- BFalsch
40float *fnum = 3.1415
- Ais invalide because you cannot assign a number to a pointer
- Bstores 3.1415 in fnum.
- Cstores 3.1415 at the address where fnum points at.
- Dis not a valid statement because a pointer cannot be a fraction.
41The debug macros in dbg.h will automatically detect errors in the code and print them out
- ARichtig
- BFalsch
42You should always compile your code using the command line switch to include debugging info.
- ARichtig
- BFalsch
43kill stops and deletes the program being debugged.
- ARichtig
- BFalsch
44clear 157 deletes the instruction at line 157.
- ARichtig
- BFalsch
45display sum prints out the value of the variable sum each time the program stops at a breakpoint or watchpoint.
- ARichtig
- BFalsch
46Using dbg.h and scattering debug messages through the source code is less efficient than using gdb.
- ARichtig
- BFalsch
47continue lets the program run until it hits the next breakpoint or the program ends.
- ARichtig
- BFalsch
48watch x*y stops execution of the program if the value x*y changes. x and y must be defined in the program.
- ARichtig
- BFalsch
49step causes the program to execute one line at a time, slowly, so you can watch the execution.
- ARichtig
- BFalsch
50If a debug macro from dbg.h is triggered, it will print the file and line number of the source code that triggered it.
- ARichtig
- BFalsch
51list myprog:15 myprog:27 will display the source code from lines 15–27 from myprog.
- ARichtig
- BFalsch
52info watchpoints lists information about the watchpoints that have been set.
- ARichtig
- BFalsch
53gdb -args ./myprog 7 9 creates a debug session for the program myprog and passes 7 and 9 to it as arguments.
- ARichtig
- BFalsch
54break myprog:sum tells the debugger to stop execution when it reaches the sum function in myprog.
- ARichtig
- BFalsch
55next goes to the next instruction. If the next instruction is a function call, then it goes to the first instruction inside the function.
- ARichtig
- BFalsch
56print x+5 will print 5 added to the value of x, presuming x is defined in the program being debugged.
- ARichtig
- BFalsch
57list myprog:sum displays the source code for the sum function in myprog.
- ARichtig
- BFalsch
58-d is the argument to gcc to compile the code in a debuggable state.
- ARichtig
- BFalsch
59Bracketing a bug with debug messages or even just print statements can be faster than stepping through the code with debug.
- ARichtig
- BFalsch
60info break displays information about the last breakpoint reached.
- ARichtig
- BFalsch
61A break statement in a loop will cause the current loop iteration to halt and execution of the next loop iteration to begin.
- ARichtig
- BFalsch
62The reserved word else is always associated with the closest if statement unless braces are used to define blocks of statements.
- ARichtig
- BFalsch
63Declarations can be placed anywhere in the program.
- ARichtig
- BFalsch
64If a condition's value is 0, then the condition is evaluated as true.
- ARichtig
- BFalsch
65Blocks of statements can be grouped by brackets("{" and "}") which must be followed by a semicolon.
- ARichtig
- BFalsch
66A continue statement will cause a loop to ignore subsequent break statements.
- ARichtig
- BFalsch
67The execution of a program begins with the main function.
- ARichtig
- BFalsch
68If a break is not included at the end of a switch case, execution will continue to the next case.
- ARichtig
- BFalsch
69C is not case sensitive.
- ARichtig
- BFalsch
70A while loop will always execute once.
- ARichtig
- BFalsch
71Given x = 45, the statement printf("The result is %x."); will print out "The result is 45."
- ARichtig
- BFalsch
72If a condition's value is 34, then the condition is evaluated as true.
- ARichtig
- BFalsch
73A for loop must have the loop variable initialized before the loop statement.
- ARichtig
- BFalsch
74The result of an integer division is a rounded result.
- ARichtig
- BFalsch
75The number of specifiers in a format string must match the number of variables following it in the call to printf, even if that number is 0.
Ex: printf("This has two specifiers and variables: %d and %d", x, y); and printf("This has no specifiers");- ARichtig
- BFalsch
76Statements and declarations, but not directives or comments, must end with a semicolon.
- ARichtig
- BFalsch
Informationen
- Beschreibung
- Computer Science Quiz am C Programming, erstellt von John Jackson am 16/10/2019.
- Autor
- John Jackson
- Sprache
- English
- Aufrufe
- 2
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz