Intro to C Programming Test 1 Study Guide

Ace your homework & exams now with Quizwiz!

Every preprocessor directive must begin with a _______________.

# symbol

The ___________________ operator concatenates its two arguments.

##

Write a preprocessor directive that defines the macro MIN2 that determine the smallest of two numeric values input from the keyboard.

#define MIN2(a, b) ((x < y)?x:y)

Create #define statements to accomplish the following goals: a. Create a named constant of value 25 b. Have PS() represent printing the space character c. Have BIG(X) represent adding 3 to x.

#define VALUE 25 #define PS() printf(" "); #define BIG(X) x + 3

How do you define a macro?

#define at the top of the file.

The conditional compilation construct may be extended to test for multiple cases by using the ____________ and _________________ directives

#else and #elseif

What are the main headers to add in a C program?

#include <stdio.h> #include <stdlib.h>

What is the header format?

#include <stdio.h> #include <stdlib.h> int main() { }

printf() Conversion Identifiers

%d is an integer %o is an octal integer %x is a hex integer %u is an unsigned integer %c is a character %s is a string %f or %lf is a double %e %E is a double (converts to scientific notation) %g %G is a double (chooses the shortest between decimal and scientific notation)

The __________ flag causes output to be left justified in a field.

- symbol

What is the output of: int x = 0; while (++x < 3) printf("%4d", x);

1 2

What is the output of: #include <stdio.h> #define TEN 10 int main(void) { int n = 0; while (n++ < TEN) printf("%5d\n", n); printf("\n"); return 0; }

1 2 3 4 5 6 7 8 9

What are the trigraphs in C?

??= is # ??( is [ ??) is ] ??/ is \ ??< is { ??> is } ??! is | ??' is ^ ??- is ~

Why would you use a type long variable instead of type int?

A long int has more usable values than an int or short int

What is a nested loop?

A loop within a loop.

What is a preprocessor?

A substitution tool in C that allows to make directives and macros.

What main methods come from <stdio.h>

All standard input and output functions.

How are characters stored in C?

As integers

What's the difference between binary files and text files on the one hand versus binary streams and text streams on the other?

Binary files are a sequence of bytes or ordered groupings of eight bits. This could store data of the same type, such as a video or picture. Text files can only have textual data. Read through EOL and EOF methods. Binary streams have multiple bytes of data in a file. Text streams have multiple lines of data in a file.

What is the min and max value of a float?

Changes between computers and compilers. Between int and double.

What is the min and max value of a double?

Changes between computers and compilers. Largest data type.

What is the min and max value of an int?

Changes between computers and compilers. Smaller than a float.

_________________ enables you to control the execution of preprocessor directives and the compilation of program code.

Conditional Compliation

How do you define a constant?

Either do a #define statement or put const before the variable. All constants are all uppercase as common practice.

What is EOL and EOF?

End of Line and End of File

Write a program which compares two text files, f1 and f2, one character at a time. Prints message if they are equal or not equal.

FILE *a, *b;

How do you declare a file?

FILE fileName; Before fileName you must put a *

White space matters in C (T/F)?

False

If the file position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file

False You can use the rewind() function.

How do you read a file until the end of a line?

For Characters: while(ch = fgetc(fileHandle) != '\n'); For Integers: while(fscanf(a, "%d", &arrayA[i]) != '\n');

How do you read a file until the end of the file?

For Characters: while(ch = fgetc(fileHandle) != EOF); For Integers: while(fscanf(a, "%d", &arrayA[i]) != EOF);

What happens when you try to print a double as an int?

It will cause an error, and print nothing.

How long can Identifiers be for an element?

Only tracks first 21 characters. If extern only first 6 characters.

How do you change regular methods to file methods?

Put an f before it.

What does the scanf() function do?

Returns how many elements it has scanned. Useful for seeing if there is more than one element.

What is the difference between signed and unsigned?

Signed int values include -32767 to 32767 Unsigned int values include 0 to 65535

What types of files can be read in C?

Text files and Binary files.

What's the difference among the following? printf("Hello, %s\n", name); fprintf(stdout, "Hello, %s\n", name); fprintf(stderr, "Hello, %s\n", name);

The first piece of code is just simply displaying the text "Hello, %s" to the screen. %s being a variable with a name. The second is printing the same text, but to the file "stdout" instead of displaying it on screen. The third is an error, which will appear in a different color, as it is used to send errors if something is not right.

What is a macro?

The name of a preprocessor that is defined to do certain actions.

Function fscanf() can also be used to read data from the standard input.

True The input stream can be changed in the function.

What is the output of: printf("%d\n", 10.987);

Trying to print a double with an int, will cause an error.

When does a preprocessor execute?

Whatever it is defined to execute.

How do all directives begin?

With a # symbol

What is the use of a header file?

You can call functions and prototypes to give us access to different information or tools.

What happens when a number gets too high in C?

You get a stack overflow error

What potential problem do you face when intermixing numeric input with character input on a buffered system?

You may accidentally display the wrong information. For example, the character or integer may not be the same with different data types.

The character __________________________ indicates that the replacement-text for a symbolic constant or macro continues on the next line.

\ symbol

What are the C data types?

char, int, float and double

What are the primitive data types?

char, int, float and double

What is the general function form in C?

data_type(parameters) { } Data type can be void if it isn't returning anything. Does not need parameters. Name of file must include .h at the end, and must have a #include "" statement in main file.

The _____________________directive creates macros and symbolic constants.

define

The conversion specifier _____________ is used to display a floating-point value in exponential form.

e

Function ____________ closes a file.

fclose();

How do you close a file?

fclose(fileHandle);

How to read and write a single char?

fgetc() and fputc()

Function ______________ reads a character from a specified file.

fgetc();

What are the types of decimals in C?

float and double

How to read a single integer?

fscanf(fileName, "%d", &variable);

The modifiers __________ and ______________ are placed before the integer conversion specifiers to indicate that short or long integer values are to be displayed.

h and l

Write a boolean function: int between (int x, int y, int z) Which returns 1 if z is between x and y (including both x and y) and 0 otherwise.

if(z <= x && z >= y) return 1; else return 0;

Identify the data type and printf() format specifier for: 12

int, %d

Output Statement

printf() Same as the printf() function in Java Format changes, for integers it is printf("%d", i);

How do you print a line of code?

printf(); Same format as Java.

What are the open modes when opening a file?

r is Read w is Write (overwrite existing file) a is Append r+ is Reading + Writing (new data is written at the beginning, overwriting existing data) w+ is Reading + Writing (overwrite existing file) a+ is Reading + Appending (new data added to end of the file)

How do you end a program?

return EXIT_SUCESS; or return EXIT_FAILURE;

Input Statement

scanf() Format changes, for integers it is scanf("%d", &i); When scanning values, must but & before the variable

How do you scan from a keyboard?

scanf(); Must include & before the variable when scanning in a value.

What are the types of integers?

short and long, signed and unsigned

The ______________ stream should be used for error messages.

standard error

The ___________ stream is normally connected to the keyboard.

standard in

The _______________ stream is normally connected to the computer screen.

standard out

What is the output of: char ch = 's'; while (ch < 'w') ch++; printf("%c\n", ch);

stuvw

Only _________________ characters may appear before a preprocessor directive on a line.

whitespace

What is x & y: y = x = (2 + 3)/4;

x = 1, y = 1

What is x: x = (12 + 6)/2 * 3;

x = 27

What is x & y: y = 3 + 2*(x = 7/2);

x = 3, y = 9

What is x: x = (2 + 3) * 6;

x = 30

What is the difference between x++ and ++x?

x++ will use the number and then add. ++x will add the number and then use it.


Related study sets

Social Perception and Attribution vocab practice and quiz

View Set

Real Estate Mathematics and Formulas

View Set

Earth Space Science Technology and the EMS

View Set

OB: Ch. 18 Nursing Management of the Newborn

View Set

Fundamentals of Nursing CH 4: Health and Illness

View Set