You are on page 1of 9

COMPUTER PROGRAMMING

DEV C++

I. BASIC PARTS
LIBRARY/HEADER TYPES OF DATA

Type Description Format


Specifier
#include<stdio.h>
int main () int Whole numbers excluding %d, %i
{ VOID decimal values
printf(“I am Ardent”); char Use for declaring character %c
return 0; type variables
} string Series of characters %s
terminated with a null
character \0
float Use to hold real numbers %f
double Use to hold real numbers %lf
MAIN BODY short int Small integer value %hd
unsigned Permits only positive integer %u
EXIT PAGE int values to be stored
long int Long signed integer type. %ld, %li
Capable of holding [-
II. HEADERS 2,147,483,647, -
2,147,483,647 ] range
▪Header files are libraries that are used in a long Capable of containing 2^63- %lld, %lli
program to use existing functions for an easier long int 1 digits
process. unsigned Capable of containing [0, %lu
long int 4,294,967,295] range
unsigned Capable of containing %llu
▪These header files are used in programs by long 18,446,744,073,709,551,615
#include. long int digits
signed Capable of containing %c
▪These files have a .h extension at the end. char [-127,127] characters
unsigned Capable of containing [0, %c
char 255] characters
Types of Headers long Real floating-point type, %Lf
double usually mapped to an
(1) Pre-existing header files extended precision floating-
Files which are already available in C/C++ point number format
compiler we just need to import them.

(2) User-defined header files SYNTAX RULES


These files are defined by the user and can be
imported using “#include”. Means how to arrange words, characters,
special characters, to make a meaningful
statement, or expression, etc.
III. DATA TYPES
The set of rules that must be followed while
FORMAT: dataType variable_name = value; developing a program.

Header File Description


▪Limit the kind of data that may be stored.
stdio.h Input/Output Functions
stdlib.h General Utility Functions
▪Used to inform variables about the sorts of
data they may hold.

▪Declarations for variables.


SYMBOLS
▪Also known as Special Characters.

▪Characters with “special” built-in meanings in


the language can not be used as identifiers.

▪A primitive data type with a distinct human-


readable form.

Symbol Library Description e.g. Use of constants


[] Brackets Are used to denote
single and COMMENTS
multidimensional
subscripts in an array
() Parentheses Are special symbols that ▪Add clarity to the source code.
are used to call functions
and pass parameters to ▪Crucial in large projects with hundreds or
them thousands of lines of source code.
{} Curly Marks the beginning and
Brackets end of a block of code Single-Line Comments - starts and ends in
that contains more than the same line.
one executable
statement by opening Multi-Line Comments - comment on multiple
and closing it
lines at once.
, Comma Marks the beginning and
end of a block of code
that contains more than
one executable
statement by opening
and closing it
: Colon Is an operator who calls
up an initialization lists
: Semicolon Is a statement terminator Single-Line Comment
that marks the end of
one logical entity
* Asterisk It is used to create a
pointer variable Multi-Line Comment
= Assignment It is used for assigning
Operator values
# Preprocesso Is used by the compiler RESERVED WORDS
r to transform your ▪Predefined, reserved words used in
program before the programming that have special meanings to
actual compilation starts the compiler
\\ Back Slash Single line comment

CONSTANTS
▪Fixed values that the program may not alter
once they’re set that are also called literals.

▪Handled like ordinary variables except that


their values cannot be updated after
declaration.

▪It can be of any of the basic data types.

▪e.g. integer numerals, floating-point numerals,


characters,strings, Boolean Values.
MEMORY ALLOCATIONS
Two types: (1) Simple Assignment Operator;
▪RAM (Random Access Memory)-the type of (2) Compound Assignment Operator
memory in which the computer keeps the
instructions for currently running programs
Operator Example Same As
▪Those sizes can be different for different = x=y x=y
platforms but the most usual is something like: += x+=y x=x+y
▪char: 1 byte -= x-=y x=x-y
▪short: 2 bytes *= x=y x=x*y
▪int: 4 bytes /= x/=y x=x/y
▪float 4 bytes # x%=y x=x%y
▪double 8 bytes

ARITHMETIC OPERATORS

▪Are the foundation for determining how


computed figures or goods will turn out.

▪Used linearly, with addition and subtraction


coming after multiplication and division in the
order of operation.

Operator Meaning Description


+ Addition Add two operators
- Subraction Subtract
* Multiplication Multiply BITWISE OPERATORS
/ Division Divide
% Modulo Modulus operator Operator Meaning
Division and remainder of & Bitwise AND
after an integer l Bitwise OR
division ^ Bitwise XOR
++ Increment Add one ~ Bitwise Complement
-- Decrement Minus one << Shift Left
>> Shift Right

ASSIGNMENT OPERATORS

These assign the value or result of an


expression to a variable.

Variables are on the left-hand side, while


values/expressions are always on the right-
hand side.
PRE-DEFINED MATH FUNCTIONS

To use the built-in math functions, we


need to include the math.h library.

Function Description
1. pow Exponent
2. sqrt Square root
3. fabs Absolute value
4. abs Absolute value
5. ceil Ceiling
6. floor Floor
7. fmax Maximum
8. fmin Minimum
9. round Round up or down
10. remainder Return to nearest value

PREDEFINED STRING FUNCTIONS

CODE
Examples:
TYPECASTING SWITCH STATEMENTS

converting one data type into another one ▪a multiway branch statement.
Syntax: (data type) expression
▪offers a simple method for allocating execution to
(data type) - value that we want to convert, whether various sections of code according on the
a literal value, a variable, or the result of an expression’s value.
expression.
▪provides a straightforward technique for assigning
expression - the “destination” data type that we execution to different code segments in
want to convert the expression to. accordance with the value of the expression.

TYPES OF TYPECASTING

(1) Implicit Type Casting - convert a data type of


a variable into another data type without losing its
actual meaning.

(2) Explicit Typecasting - data type is not


converted automatically; force the conversion
between data types.
RELATIONAL STRUCTURES

These test or define a relationship between two


elements.

Used in determining the relationship between the


two numbers.

BOOLEAN OPERATORS

used to carry out Boolean logic operations utilizing


Boolean expressions to arrive at a logical
conclusion

used when one needs to evaluate several relational


expressions to return a single value
SELECTION STRUCTURE IF ELSE STATEMENT

enables the program to decide and alter its If a condition is true, the if statement will
behavior in response to that choice. execute a block of statements, but if the
condition is false, the else statement kicks in.
one or more conditions that will be evaluated
or tested by the program. else statements work similarly to if statements,
but their condition is solely dependent on the if
(1) if statement statement’s condition.
consists of a boolean expression followed by
one or more statements.

(2) if…else statement


can be followed by an optional else statement,
which executes when the boolean expression
is false.

(3) switch statement


allows a variable to be tested for equality
against a list of values.

IF STATEMENT

most basic decision-making condition; involve


only one condition to be met for the code
inside it to be performed.

IF ELSE ELSE STATEMENT


the if...else “ladder” allows you to go back and
forth between various test expressions and
statements
NESTED DECISION

used when you must test a combination of


conditions before deciding on the proper action.

You might also like