Assessments
You'll find the answers to all questions here.
You'll find the answers to all questions here.
void
.Char
, signed char
, unsigned char
, short
, short int
, unsigned short int
, int
, long int
, unsigned long int
, float
, double
, long double
, and _Bool
.=
assignment operator.AND
, OR
, XOR
, and NOT
.( )
parentheses operator.if()… else…
statement is to provide a branch so that either one or the other branch of the statement will only be executed.if()…
statement can be replaced with a switch()…
statement because the conditional expression of an if()…
statement can consist of multiple conditions resolving to a single Boolean value, whereas a switch()…
statement generally tests for single values.switch()…
statement.else
problem is to use brackets ({…}
) for each branch of the if()… else…
statement.for()…
, while()…
, and do … while()
loop statements and the goto label
pair.true
, signaling the end of looping.while()…
loop is zero. If the loop condition is false
, the loop body never executes. The maximum number is an infinite loop when the loop condition is never false
.do … while()
loop is one. The loop body will always execute once the loop condition is evaluated. The maximum number is an infinite loop when the loop condition is never false
.for()…
loop is ideal for counter-controlled looping. The while()…
and do … while()
loops...case: condition
must be unique within that switch()…
statement.struct someName s = {0};
struct someName s1, s2;
s2 = s1;
struct someName s = { value1 , value2, … , value2 };
to initialize the components of a structure variable is the compact expression of this initialization, especially when there are many such structure variables to be initialized.enum
types, as well as other structures. We will see later that a component may also be an array of any of these.typedef
keyword allows us to create synonym types that add context to variables of that type.typedef
provides a shorthand synonym. Instead of using enum List
, we can use typedef
to shorten it to just List
. Instead of using struct Gizmo
, we can use typedef
to shorten it to just Gizmo
. Then, we can declare variables of List
and Gizmo
synonym types. –Wall
and –Werror
switches instruct the compiler to treat any warning as an error and to cause all errors, no matter how trivial, to stop compilation. typedef
, enum
, struct
, and function prototypes) goes into a header file. Anything that allocates memory or defines functions goes into the source file, not the header.#define
symbol, a constant expression (such as 13-3
), or an enumeration constant.0
(NULL
) up to the largest addressable byte in memory. void*
type, which is unknown and must be provided to access the value it points to.NULL
(no target) or the location of an already-allocated memory location (such as an intrinsic variable, a structure variable, or an array variable).NULL
character.NULL
character and any array elements after that can be ignored. A string array can never hold more characters (including the NUL
character) than the size of the array.'x'
is a single character. "x"
is a C string of one character with the NULL
character.NULL
character. A NULL
string is a declaration of a string array or a pointer to a string array that has never been allocated."Hello"
literal string is only modifiable when it is used as an initializer to a constant...Card
is a simple structure of intrinsic and enumerated types.Hand
is a structure that consists of an array of pointers.Deck
is a structure that consists of an array of structures, an array of pointers, and intrinsic types.Face
and Suit
that are related to each other use the e-
prefix. In the other case, enumerated constants for array sizes are unrelated and use the k-
prefix. auto
, static
, extern
(global), and register
.malloc()
allocates requested memory on the heap, as does calloc()
. However, calloc()
initializes the allocated memory to zero before returning.free()
deallocates that memory or when the program ends.printf()
converts values (binary patterns) into characters for display on the console.printf()
are copied (call by value) and, therefore, cannot be changed by printf()
.printf()
can only print the intrinsic types given in this chapter. Custom functions must be created to print the elements of a given structure.main()
: one that takes no parameters and one that takes an argument count and an argument vector.argv
parameter provides an array of strings entered on the command line to our program. They are strings only and may have to be converted to other data types in the argument processing loop.getopt()
, which is part of the C Standard Library, is system implementation-dependent. However, getopt()
, as specified by the C standard, can be considered a minimum set of functionality and behavior; other implementations add additional capabilities.stdin
), console output (or stdout
), and console error output (or stderr
). These three streams are declared in stdio.h
.scanf()
to convert input directly to the desired type with a format string; second, use fgets()
to read input into a buffer and use sscanf()
to convert data in the buffer to the desired type; or third, again read input into a buffer and use atoi()
or atod()
to convert data in that buffer to the desired type.gets()
, even if it is available.fgets()
from stdin
; for newer versions of C, use gets_s()
.stdin
, stdout
, and stderr
are console streams. A hard drive, a floppy drive, a CD, and a DVD are file-streaming devices. A microphone and speakers are audio-streaming devices. A network interface is both an input and output streaming device.<newline>
character when using fgets()
depends upon the context in which fgets()
is used. In the last chapter, we used a wrapper function around fgets()
. In this chapter, we didn't need to do that, since the trimStr()
function is always used after fgets()
, which removes all leading and trailing whitespace.main()
, or as a global variable (as we did with bRandomize
).#ifndef _HEADER_NAME_H_
, #define _HEADER_NAME_H_
, and #endif
macros around the contents of the header file.main()
function and doesn't rely upon any other source files/compilation units, it may be a complete program. Not all compilation units are complete programs.Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com
for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.