GMU CS262 Final Exam Spring 2022

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

How do you include the standard IO library?

#include <stdio.h>

Given 2 numbers a and b, how would you write a statement that returns the maximum values between the two within 1 line?

(a >= b) ? a : b

What are symbolic constants in C

A name given to some numeric constant, character, or string. (#define <name>)

What is 5! (5 factorial)

5 * 4 * 3 * 2 * 1 = 120

What is the command to go to a specific line within vim?

:<line number>

Within vim, what is the command to exit the vim?

:q

Within vim, what is the command to save the current file?

:w

Why can you subtract an integer from a character?

The character's ASCII value encoding value to turn it into an integer.

What is the entry point for a C program?

The main function

What is assembling?

The stage where it translates the assembly language program into executable binary code.

What is the default value of a variable in C?

There is no value. It's uninitialized // data is unknown

How do you get integer input from the user?

int num; char inBuf[15]; printf("\nEnter a number: "); fgets(inBuf, 15, stdin); sscanf(inBuf, "%d", &num);

How can you use the make command to compile "playground.c" and create an executable called "playground"

make playground

What command can you show the documentation for the command "printf"

man printf

Use the "printf" function to print a variable "num" of type double with 2 decimal point precision.

printf("%.2lf", num);

What unix command lets you see the processes you are running?

ps

How do you generate a random number with a range between -5 and 5?

rand() % 11 - 5

How do you generate a random number between 0 and 5 (inclusive)?

rand() % 6

What is the command, from your local computer, to download "playground.c," which is in your Zeus home directory?

scp [email protected]:~/playground.c

via the sscanf method, how do you obtain 2 numbers on the same line, with a space in between them, and assign variables "a" and "b" to them

sscanf(buffer, "%d %d", &a, &b);

How do you get the length of a string?

strlen(<string>)

What is the function to concatenate a string to another string?

strncat(<dest>, <src>, <max number of characters>);

How would you write a function to copy a string from variable "temp" to variable "copied" and you only want to copy a certain amount of characters

strncpy(copied, temp, sizeof(copied));

Make a struct "player" with the fields "name", and integer "heightInInches". It should also have an alias of "Player"

typedef struct player { char name[100]; int heightInInches; } Player;

How do you instruct GCC to produce an object file within the assembling stage?

use the -c option

What is the linking stage within the compiling process?

Once you have all the separate pieces of object code, the linker fits them together to form the executable program.

How do you check to see if two strings are equal to each other?

if(strncmp(<s1>, <s2>) == 0)

What are main's parameters for CLI (Command line) arguments?

int argc, char *argv[] (can also be char **argv)

Give the command to run "playground" redirecting in input.dat as the input?

./playground < input.dat

Give the command to run "playground" redirecting in input.dat as the input and redirecting output to output.txt

./playground < input.data > output.txt

Give the command to run "playground" redirecting in output.txt as the output?

./playground > output.txt

What file extension do files that are generated by compilation have?

.s

int get_counter(){ int val = 0; return val++ } What value is returned?

0

What does the expression 9 / 5 give you?

1

What is the size, in bytes of a char?

1

What is the heap?

A segment of program memory for dynamically allocated variables

What is the stack?

A segment of program memory for local variables. Subject to scope

What is preprocessing?

Creates a modified version of the source file. You can generate output by using the -E option. It creates files with the extension .i

How do you free an allocated variable "ptr"?

free(ptr); ptr = NULL;

What does the preprocessor do with symbolic constants?

It replaces all references of constants with its actual value within the code.

What is compiling?

It translates C programs into the machine's assembly language.

What does it mean for a variable to be static?

It's value doesn't perish until the program ends (Even if it's a local variable within another method)

How do you fix integer division?

Make one of the numbers a double.

What is the size, in bytes of an int?

System dependent??

What does cd ~ do?

Takes you to your home directory

How do you stop the compiling process?

Using the -S option

What data type do you get when you divide two integers in C?

You get an integer back. Example: 9 / 5 = 1. 5 Goes into 9 1 time.


Conjuntos de estudio relacionados

Nursing 351 Ethical Issues in Nursing

View Set

Nursing prep u GI disorders upper and lower

View Set

California Hunter Safety - Unit 8 Quiz

View Set

mastering in geology part 2 part 2

View Set

General Psychology Unit 2 (Chapters 5-8)

View Set