C Programming Language Flashcards
tokens
A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.
a statement terminator
semicolon
each individual statement must be ended with
a semicolon
a name used to identify a variable, function, or any other user-defined item
identifier
C does not allow _ within identifiers
punctuation characters such as @, $, and %
Is C case-sensitive?
YES
A C compiler totally ignores __
A line containing only whitespace, possibly with a comment, a blank line,
Categories of types in C
basic, enumerated, void, derived
char (bytes, range)
1 byte, -128 to 127 or 0 to 255
unsigned char (bytes, range)
1 byte, 0 to 255
signed char (bytes, range)
1 byte, -128 to 127
int (bytes, range)
2 or 4 bytes, -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int (bytes, range)
2 or 4 bytes, 0 to 65,535 or 0 to 4,294,967,295
short (bytes, range)
2 bytes, -32,768 to 32,767
unsigned short (bytes, range)
2 bytes, 0 to 65,535
long (bytes, range)
8 bytes or (4bytes for 32 bit OS) , -9223372036854775808 to 9223372036854775807
unsigned long (bytes, range)
8 bytes, 0 to 18446744073709551615
float (bytes, precision)
4 byte, 6 decimal places
double (bytes, precision)
8 byte, 15 decimal places
long double (bytes, precision)
19 decimal places
three situations for void
functions returning void, function arguments as void, pointers to void
A pointer of type void * represents
the address of an object, but not its type
what is a variable?
A variable is nothing but a name given to a storage area that our programs can manipulate.
basic types of variables
char, int, float, double, void
At what time does a variable definition have its meaning?
compilation time
extern keyword
declare a variable at any place. Though you can declare a variable multiple times in your C program, it can be defined only once in a file, a function, or a block of code.
Two types of C expressions
lvalue and Rvalue
lvalue
Expressions that refer to a memory location; can be on left side or right side
rvalue
refers to a data value that is stored at some address in memory. An rvalue is an expression that cannot have a value assigned to it which means an rvalue may appear on the right-hand side but not on the left-hand side of an assignment.
fixed values that the program may not alter during its execution
constants a.k.a literals; values cannot be modified after their definition.
Four storage classes
auto, register. static, extern
default storage class for all local variables
auto
‘auto’ storage class. can only be used…
within functions, i.e., local variables.
storage class used to define local variables that should be stored in a register instead of RAM
register
What does the register storage class mean?
This means that the variable has a maximum size equal to the register size (usually one word) and can’t have the unary ‘&’ operator applied to it (as it does not have a memory location).
Does using the register storage class mean that the variable will DEFINATELY be stored in the register?
It should also be noted that defining ‘register’ does not mean that the variable will be stored in a register. It means that it MIGHT be stored in a register depending on hardware and implementation restrictions.
storage class that instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope.
static; Therefore, making local variables static allows them to maintain their values between function calls.
What happens when the static modifier is applied to global variables?
it causes that variable’s scope to be restricted to the file in which it is declared.
storage class that causes only one copy of that member to be shared by all the objects of its class.
static
storage class used to give a reference of a global variable that is visible to ALL the program files
extern
storage class where the variable cannot be initialized
extern
storage class which points the variable name at a storage location that has been previously defined
extern
The header file stdio.h stands for
Standard Input Output. It has the information related to input/output functions.
The header file stdlib.h stands
for Standard Library. It has the information of memory allocation/freeing functions.
a symbol that tells the compiler to perform specific mathematical or logical functions
operator
types of operators
Arithmetic, Relational, Logical, Bitwise. Assignment
Misc
By default, C uses call by _____ to pass arguments.
value
a kind of data structure that can store a fixed-size sequential collection of elements of the same type
array
All arrays consist of _ memory locations
contiguous
C programming does not allow to return an entire array as an argument to a function. However, you can return a _______ by _________.
pointer to an array; specifying the array’s name without an index.
pointer
a variable whose value is the address of another variable
The actual data type of the value of all pointers, whether integer, float, character, or otherwise
a long hexadecimal number that represents a memory address
The only difference between pointers of different data types is
the data type of the variable or constant that the pointer points to
A pointer that is assigned NULL
a null pointer
In several standard libraries, The NULL pointer is a constant with a value of
zero
In most of the operating systems, programs are not permitted to access memory at address
0
A variable that is a pointer to a pointer must be declared as such. This is done by ______.
placing an additional asterisk in front of its name
There are four arithmetic operators that can be used on pointers:
++, –, +, and -
string
one-dimensional array of characters terminated by a null character ‘\0’
Why is the size of a character array containing a string is one more than the number of characters?
To hold the null character at the end of the array
used to represent a record and to combine data items of different kinds
structures
a union
a special data type available in C that allows to store different data types in the same memory location
You can define a union with many members, but ____.
only one member can contain a value at any given time
bit fields
the variables defined with a predefined width
a keyword which you can use to give a type a new name
typedef; By convention, uppercase letters are used for these definitions to remind the user that the type name is really a symbolic abbreviation, but you can use lowercase
difference between typedef and #define
typedef is limited to giving symbolic names to types only where as #define can be used to define alias for values as well, q., you can define 1 as ONE etc.
typedef interpretation is performed by the compiler whereas #define statements are processed by the pre-processor.
C programming treats all the devices as
files
reads the next available character from the screen and returns it as an integer
getChar(void); This function reads only single character at a time
puts the passed character on the screen and returns the same character.
putChar(int c); This function puts only single character at a time.
reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF (End of File).
char *fgets(char *s)
writes the string ‘s’ and ‘a’ trailing newline to stdout.
int puts(const char *s)
function reads the input from the standard input stream stdin and scans that input according to the format provided.
int scanf(const char *format, …)
function writes the output to the standard output stream stdout and produces the output according to the format provided
int printf(const char *format, …)