Docsity

Intro to C Programming Test 1 Study Guide, Exams of Health sciences

Toggle sidebar
bg1
Intro to C Programming Test 1 Study
Guide
Start a student pass
Assign an activity
What are the C data types? - ANSWER...-char, int, float and double
What is the header format? - ANSWER...-#include <stdio.h>
#include <stdlib.h>
int main()
{
}
Input Statement - ANSWER...-scanf()
Format changes, for integers it is scanf("%d", &i);
When scanning values, must but & before the variable
Output Statement - ANSWER...-printf()
Same as the printf() function in Java
Format changes, for integers it is printf("%d", i);
printf() Conversion Identifiers - ANSWER...-%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)
What is x:
x = (2 + 3) * 6; - ANSWER...-x = 30
What is x:
x = (12 + 6)/2 * 3; - ANSWER...-x = 27
What is x & y:
y = x = (2 + 3)/4; - ANSWER...-x = 1, y = 1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Intro to C Programming Test 1 Study Guide and more Exams Health sciences in PDF only on Docsity!

Intro to C Programming Test 1 Study

Guide

Start a student pass Assign an activity What are the C data types? - ANSWER...-char, int, float and double What is the header format? - ANSWER...-#include #include int main() { } Input Statement - ANSWER...-scanf() Format changes, for integers it is scanf("%d", &i); When scanning values, must but & before the variable Output Statement - ANSWER...-printf() Same as the printf() function in Java Format changes, for integers it is printf("%d", i); printf() Conversion Identifiers - ANSWER...-%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) What is x: x = (2 + 3) * 6; - ANSWER...-x = 30 What is x: x = (12 + 6)/2 * 3; - ANSWER...-x = 27 What is x & y: y = x = (2 + 3)/4; - ANSWER...-x = 1, y = 1

What is x & y: y = 3 + 2(x = 7/2); - ANSWER...-x = 3, y = 9 What is the output of: printf("%-10d\n", 10000); - ANSWER...- What is the output of: printf("%.*lf\n", 8, 3, 1024.987654); - ANSWER...- What is the output of: printf("%#o\n%#X\n%#e\n", 17, 17, 1008.83689); - ANSWER...- What is the output of: printf("% ld\n%+ld\n", 1000000, 1000000); - ANSWER...- What is the output of: printf("%10.2E\n", 444.93738); - ANSWER...- What is the output of: printf("%10.2g\n", 444.93738); - ANSWER...- What is the output of: printf("%d\n", 10.987); - ANSWER...-Trying to print a double with an int, will cause an error. What is the output of: printf("He sold the painting for $%2.2f.\n", 2.345e2); - ANSWER...- What is the output of: #include #define TEN 10 int main(void) { int n = 0; while (n++ < TEN) printf("%5d\n", n); printf("\n"); return 0; } - ANSWER...- 1 2 3 4 5 6 7 8

The ___________ stream is normally connected to the keyboard. - ANSWER...- standard in The _______________ stream is normally connected to the computer screen. - ANSWER...-standard out The ______________ stream should be used for error messages. - ANSWER...- standard error The modifiers __________ and ______________ are placed before the integer conversion specifiers to indicate that short or long integer values are to be displayed. - ANSWER...-h and l The conversion specifier _____________ is used to display a floating-point value in exponential form. - ANSWER...-e The __________ flag causes output to be left justified in a field. - ANSWER...-- symbol The conversion specifier ________________ can be used to input optionally signed octal, decimal and hexadecimal integers. - ANSWER...- A(n) _____________ can be used in a scanf conversion specifier to indicate that a specific number of characters or digits should be read from the input stream. - ANSWER...- Function ____________ closes a file. - ANSWER...-fclose(); Function ______________ reads a character from a specified file. - ANSWER...-fgetc(); Function ______________ opens a file. - ANSWER...- How do you open a file? - ANSWER...- How do you close a file? - ANSWER...-fclose(fileHandle); How do you read a file until the end of a line? - ANSWER...-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? - ANSWER...-For Characters: while(ch = fgetc(fileHandle) != EOF); For Integers: while(fscanf(a, "%d", &arrayA[i]) != EOF);

Why would you use a type long variable instead of type int? - ANSWER...-A long int has more usable values than an int or short int Write a preprocessor directive that defines the macro MIN2 that determine the smallest of two numeric values input from the keyboard. - ANSWER...-#define MIN2(a, b) ((x < y)?x:y) 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. - ANSWER...-FILE *a, *b; 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. - ANSWER...-if(z <= x && z >= y) return 1; else return 0; 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. - ANSWER...-#define VALUE 25 #define PS() printf(" "); #define BIG(X) x + 3 What's the difference between binary files and text files on the one hand versus binary streams and text streams on the other? - ANSWER...-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's the difference among the following? printf("Hello, %s\n", name); fprintf(stdout, "Hello, %s\n", name); fprintf(stderr, "Hello, %s\n", name); - ANSWER...-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.

Same format as Java. How do you scan from a keyboard? - ANSWER...-scanf(); Must include & before the variable when scanning in a value. What are the main headers to add in a C program? - ANSWER...-#include #include What are the open modes when opening a file? - ANSWER...-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) White space matters in C (T/F)? - ANSWER...-False What are the trigraphs in C? - ANSWER...-??= is # ??( is [ ??) is ] ??/ is ??< is { ??> is } ??! is | ??' is ^ ??- is ~ How long can Identifiers be for an element? - ANSWER...-Only tracks first 21 characters. If extern only first 6 characters. What are the primitive data types? - ANSWER...-char, int, float and double What are the types of integers? - ANSWER...-short and long, signed and unsigned What is the difference between signed and unsigned? - ANSWER...-Signed int values include - 32767 to 32767 Unsigned int values include 0 to 65535 What happens when a number gets too high in C? - ANSWER...-You get a stack overflow error

How are characters stored in C? - ANSWER...-As integers What are the types of decimals in C? - ANSWER...-float and double How do you define a constant? - ANSWER...-Either do a #define statement or put const before the variable. All constants are all uppercase as common practice. How do you end a program? - ANSWER...-return EXIT_SUCESS; or return EXIT_FAILURE; What main methods come from - ANSWER...-All standard input and output functions. How to read and write a single char? - ANSWER...-fgetc() and fputc() How to read a single integer? - ANSWER...-fscanf(fileName, "%d", &variable); What does the scanf() function do? - ANSWER...-Returns how many elements it has scanned. Useful for seeing if there is more than one element. What are the predefined file handles? - ANSWER...- What is EOL and EOF? - ANSWER...-End of Line and End of File What are the file modes? - ANSWER...- How do you change regular methods to file methods? - ANSWER...-Put an f before it. What types of files can be read in C? - ANSWER...-Text files and Binary files. What is a preprocessor? - ANSWER...-A substitution tool in C that allows to make directives and macros. When does a preprocessor execute? - ANSWER...-Whatever it is defined to execute. How do all directives begin? - ANSWER...-With a # symbol What is a macro? - ANSWER...-The name of a preprocessor that is defined to do certain actions. How do you define a macro? - ANSWER...-#define at the top of the file. What does # # do in a define statement? - ANSWER...-

Identify the data type and printf() format specifier for: 0x5.b6p12 - ANSWER...-