#include
Instructs the C preprocessor to find the text file “stdio.h” or the standard input and output.
Comments (/* */)
May span any number of lines
Main
The most important. It defines the point at which your program starts to execute.
“{“
Means begin in Braces
“}”
Means end in Braces
“//”
A comment that only spans 1 line
Printf
Standard way of producing output.
“\n”
How C handles new lines. or “Enter”
Return
Causes the value to be passed back to the operating stem.
Return 0;
Means that the code is successful.
Return 1:
Means that the code failed.
True
Statements in the body are ended with semicolons “;”
True
Indention is ignored by the compiler (but it is important in programming)
True
C is case sensitive
True
Strings are placed in double quotes (“ “)
\t
Means tab or space
Data Type
Indicates the type of data that can be represented in the value of the data element.
int: integer
A whole number
float: floating point value
A number with a fractional part
double
A double-precision floating point value.
char (enclosed in ‘ ‘)
A single character
void
Valueless special purpose type
%d
int: integer
%f
float: floating point value
%lf
double
%c
char
%s
void
True
Local Variables must be declared after the “{“
True
Global Variables must be declared after the directives
True
Valid characters are letters, digits, and “__”
True
First character cannot be a digit
True
There are 31 character for local variables
True
There are 6 global variables
True
Name must relevant to its value
Constant
Retains a constant value throughout the execution of the program
Scanf
Gets an input value from the user
True
double r;
const double pi = 3.14159;
double a;
printf("\nEnter Radius Value:\t");
scanf("%lf", &r);
without the “&” the value will retain the generated random number during the declaration.
Operators
Used to perform operations on variables and values
Arithmetic Operators
Used to perform common mathematical operations
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulus
++
Increment
--
Decrement
Increment
Increases the value of an operand by 1
Decrement
Decreases the value of an operand by 1
Unary Operators
Only operates on a single operand
Assignment Operators
Used to assign values to variables
Comparison Operators
Compare two values (or variables)
Comparison Operators
Helps to find answers and make decisions
Comparison Operators
Return Value is either 1 for true and 0 for false. These are also known as “Booelan Values”
==
Equal to
!=
Not equal to
>
Greater than
<
Less than
>=
Greater than or Equal to
<=
Less than or equal to
Logical Operators
Can test true or false. Used to determine the logic between variables/values
&&
Logical and — returns true if both are true
||
Logical or — returns true if one is true
!
Logical not — reverse, returns false is result is true
Operator Precedence
Determines the grouping of terms in an expression and decide how an expression is evaluated
<math.h>
Contains methods for performing mathematical operations
ceil (number)
Rounds up the given number
floor (number)
Rounds down the given number
sqrt (number)
Returns the square of the given number
pow (base, exponent)
Returns the power of the given number
abs (number)
Returns the absolute value of the given number
Type Casting
Converting one datatype into another
Implicit Type Casting
Converts the datatype to any variable without using the actual value.
Explicit Type Casting
Force the conversion between data types.
Advantages of Type Casting
makes the program very lightweight
type representation and hierarchies
helps programmers to convert one data type to another type