Questions and Answers
- Which Code sample will eventually cause the computer to run out of memory?
- [x]
- [ ]
- [ ]
- [ ]
- What will this code print on the screen?
- [x]
- [ ]
- [ ]
- Nothing is printed on Screen
- What is the name for calling a function inside the same function?
- recursion
- subfunction
- inner call
- infinite loop
- What does the declaration of variable c2 demonstrate?
- character arithmetic
- undefined assignment
- type conversion
- invalid declaration
- A pointer to void named vptr, has been set to point to a floating point variable named g. What is the valid way to dereference vptr to assign its pointed value to a float variable named f later in this program?
- f = _(float _)vptr;
- f = (float \*)vptr;
- f = \*(float \*)vptr;
- f = \*(float)vptr;
- What is this declaration an example of?
- a node
- a linked list
- a stack
- a binary tree
- Header files are listed using the preprocessing directive #include, and can have one of the following formats: #include <fileA> or #include "fileB". What is the difference between these two formats?
- The preprocessor will try to locate fileA in same directory as the source file, and the fileB in a predetermined directory path.
- The preprocessor will try to locate fileA in the fixed system directory. It will try to locate fileB in the directory path designated by the -I option added to the command line while compiling the source code.
- The file using the fileA syntax must be system files, of unlimited number; fileB must be a user file at a maximun of one per source file.
- The preprocessor will try to locate fileA in a predetermined directory path. It will try to locate fileB in the same directory as the source file along with a custom directory path.
- Using a for loop, how could you write a C code to count down from 10 to 1 and display each number on its own line?
- [ ]
- [ ]
- [ ]
- [x]
- What is not one of the reserved words in standard C?
- volatile
- typeof
- register
- typedef
- What does the program shown below return?
- 1
- 3
- 2
- 0
- Using the Union declaration below, how many bytes of memory space will the data of this type occupy?
- 32
- 54
- 30
- 52
- In this code sample, what is not a problem for C compiler?
- The value of PI needs to be set to 3.141593, not 3.14
- The declaration of PI needs to say const, not constant.
- The data type of PI needs to be float not int.
- The printf statement needs to use PI, not pi.
- Which is the smallest program to compile and run without errors?
- main()
- int main() {return 0;}
- main() { }
- main() { ; }
- What is optional in a function declaration?
- data type of parameters
- return type of function
- parameter names
- number of parameters
- C treats all devices, such as the display and the keyboard, as files. Which file opens automatically when a program executes?
- stdout
- stdio.h
- default.h
- string.h
- In which segment does dynamic memory allocation takes place?
- BSS Segment
- stack
- heap
- data segment
- Which function do you use to deallocate memory?
- dalloc()
- dealloc()
- release()
- free()
- In C language what are the basic building blocks that are constructed together to write a program?
- keywords
- identifiers
- tokens
- functions
- When is memory for a variable allocated?
- during the assigment of the variable
- during the initialization of the variable
- during the declaration of the variable
- during the definition of the variable
- C uses the call by value method to pass arguments to functions. How can you invoke the call by reference method?
- by using pointers
- by declaring functions separately from defining them
- by using recursive functions
- by using global variables
- A union allows you to store different `___` in the same `___`.
- Objects; Structure
- Variables; Declaration
- Data types; Memory space
- Arrays; Header file
- What is the output of this program?
- 32
- Runtime error
- -32
- 0
- What is the difference between scanf() and sscanf() functions?
- The scanf() function reads data formatted as a string; The sscanf() function reads string input from the screen.
- The scanf() function reads formatted data from the keyboard; The sscanf() function reads formatted input from a string.
- The scanf() function reads string data from the keyboard; The sscanf() function reads string data from a string.
- The scanf() function reads formatted data from a file; The sscanf() function reads input from a selected string
- What is not a valid command with this declaration?
- `printf("%c", string[1][2]);`
- `printf("%s", string[1][2]);`
- `printf("%s", string[1]);`
- `printf(string[1]);`
- What is the expression player->name equivalent to?
- `player.name`
- `(\*player).name`
- `\*player.name`
- `player.\*name`
- Which program will compile and run without errors?
- [ ]
- [x]
- [ ]
- [ ]
- What does this function call return?
- 2
- 2.000000
- a runtime error
- a compiler error
- What does this program create?
- a runtime error
- a NULL pointer
- a compile error
- a void pointer
- What is an alternative way to write the expression (\*x).y?
- There is no equivalent.
- x->y
- \*x->y
- y->x
- Compile time errors are static errors that can be found where in the code?
- in declarations and definitions
- in functions and expressions
- in syntax and semantics
- in objects and statements
- File input and output (I/O) in C is heavily based on the way it is done `___`?
- in Unix
- in C++
- in C#
- in DOS
- What does the strcmp(str1, str2); function return?
- 0 if str1 and str2 are the same, a negative number if str1 is less than str2, a positive number if str1 is greater than str2
- true (1) if str1 and str2 are the same, false (0) if str1 and str2 are not the same
- true (1) if str1 and str2 are the same, NULL if str1 and str2 are not the same
- 0 if str1 and str2 are the same, a negative number if str2 is less than str1, a positive number if str2 is greater than str1
- What is the output of this program?
- 100
- 200
- 5
- 50
- Which is _not_ a correct way to declare a string variable?
- `char *string = "Hello World";`
- `char string = "Hello World";`
- `char string[20] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'};`
- `char string[] = "Hello World";`
- Which choice is an include guard for the header file mylib.h?
- [ ]
- [x]
- [ ]
- [ ]
- How many times does the code inside the while loop get executed in this program?
- 100
- 3
- 5
- 50
- File input and output (I/O) in C is done through what?
- syntax-driven components
- native interfaces
- system objects
- function calls
- Directives are translated by the?
- Pre-processor
- Compiler
- Linker
- Editor
- The main loop structures in C programming are the for loop, the while loop, and which other loop?
- do...while
- for...in
- repeat...until
- do...until
- By default, C Functions are what type of functions?
- global
- static
- library
- system
- You have written a function that you want to include as a member of structure a. How is such as structure member defiened?
- [x]
- [ ]
- [ ]
- [ ]
- A Stack data structure allows all data operations at one end only, making it what kind of an implementation?
- FIFO
- LIFO
- LILO
- LOLI
- What does this program display?
- K
- M
- H
- G
- Describe the relationship between lvalue and rvalue.
- An lvalue may appear only on the left-hand side of an assignment; an rvalue may appear only on the right-hand side.
- An lvalue may appear only on the left-hand side of an assignment; an rvalue may appear on either the left-hand or right-hand side.
- An lvaue and an rvalue may appear on either left-hand or right-hand side of an assignment.
- An lvalue may appear on the left-hand or right-hand side of an assignment; an rvalue may appear only on the right-hand side.
- Which operator is used to access the address of a variable?
- `%`
- `**`
- `*`
- `&`
- Which add function properly returns the updated value of result?
- [x]
- [ ]
- [ ]
- [ ]
- Consider the number of the Fibonacci series below 100: 0,1,1,2,3,5,8,13,21,34,55,89. Which piece of code outputs the sequence?
- [ ]
- [ ]
- [x]
- [ ]
- Which is _not_ a storage class specifier?
- `intern`
- `extern`
- `register`
- `static`
- Which line of code, after execution, results in `i` having the value of 1?
- `for(i=1; i<=1; i++);`
- `for(i=1; i=10; i++);`
- `for(i=1; i==10; i++);`
- `for(i=10; i>=1; i--);`
- What is the value of variable c at the end of this program?
- 50
- 5
- 0
- 500
- What is _not_ one of the basic data types in C
- long double
- unsigned char
- array
- float
- What is the member access operator for a structure?
- ,
- []
- .
- :
- What standard data type provides the smallest storage size and can be used in computations?
- char
- float
- int
- short
- what does the ctype tolower() function do?
- It returns TRUE for lowercase letters of the alphabet.
- It ensures that text output uses only ASCII values (0 through 127).
- It returns FALSE for lowercase letters of the alphabet.
- It converts an uppercase letter of the alphabet to lowercase.
- Void pointer _vptr_ is assigned the address of float variable _g_. What is a valid way to dereference _vptr_ to assign its pointed value to a float variable named _f_ later in the program?
- f=(float \*)vptr;
- f=\*(float \*)vptr;
- f=\*(float)vptr;
- f=(float)\*vptr;
- The dynamic memory allocation functions are defined in which system header file ?
- stdio.h
- stdlib.h
- limits.h
- stddef.h
- A function is a set of ________.
- declarations
- statements
- variables
- objects
- How are static functions different from global functions?
- Static functions must be declared in advance of being defined.
- Static functions must be declared is a separate header file.
- Static functions always return the same value.
- Static functions can be accessed only in the file where they are declared.
- Which code example creates the string "Hello Mars" in storage buffer `hello`.