[go: up one dir, main page]

0% found this document useful (0 votes)
77 views16 pages

Useful Functions Listed by Category.: - Arithmetic Types

The document lists various useful C programming language functions grouped into categories such as mathematical functions, string manipulation functions, file input/output functions, and time/date functions. It also provides examples of functions like sqrt, strlen, fopen, clock.

Uploaded by

janardhana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views16 pages

Useful Functions Listed by Category.: - Arithmetic Types

The document lists various useful C programming language functions grouped into categories such as mathematical functions, string manipulation functions, file input/output functions, and time/date functions. It also provides examples of functions like sqrt, strlen, fopen, clock.

Uploaded by

janardhana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

useful functions listed by category.

• Mathematical functions. sqrt, pow, sin, cos, tan.


• Manipulating characters. isdigit, isalpha, isspace, toupper, tolower.
• Manipulating strings. strlen, strcpy, strcmp, strcat, strstr, strtok.
• Formatted input and output. printf, scanf, sprintf, sscanf.
• File input and output. fopen, fclose, fgets, getchar, fseek.
• Error handling. assert, exit.
• Time and date functions. clock, time, difftime.
• Sort and search. qsort, bsearch.
• Low-level memory operations. memcpy, memset.

A typical progression for Software Design is as follows.


• Requirements and specification. The required program operation is described at a general and
then a detailed level.
• Program flow. The flow of steps, decisions, and loops are planned, usually in the form of a
diagram. This stage indicates dependencies between different subtasks. That is, it defines the
sequence of operations, and the requirements for communication of data.
• Data structures. The format of variable types for passing data between functions must be
chosen in order to design function interfaces.
• Top-down and/or bottom-up design. The structure and components of the program have to
be designed. These two design paradigms facilitate organising overall structure and individual
modules, respectively.
• Coding. Having produced a plan of how the program should appear, the problem becomes a
matter of implementation. The process of coding often uncovers flaws in the original design,
or suggests improvements or additional features. Thus, design and implementation tend to be
iterative and not a linear progression.
• Testing and debugging. All non-trivial programs contain errors when first written, and should
be subjected to thorough testing before being shipped to customers. Methods for systematic
testing and debugging are beyond the scope of this text (for more information see, for example,
[KP99, Ben00]).

Data Types
Scalar types
•Arithmetic types
Integral types: char, short, int, long
Floating-point types: float, double, long double
•Pointer types
•Aggregate types
•Array types
•Structure types
•Union types
•Function types
•Void types
1 Basic Types:
They are arithmetic types and consists of the two types: a integer types and b
floatingpoint
types.
2 Enumerated types:
They are again arithmetic types and they are used to define variables that can only be
assigned certain discrete integer values throughout the program.
3 The type void:
The type specifier void indicates that no value is available.
4 Derived types:
They include

Character constants
Escape sequence| Meaning

\\ \ character
\' ' character
\" " character
\? ? character
\a Alert or bell
\b Backspace
\f Form feed
\n Newline
\r Carriage return
\t Horizontal tab
\v Vertical tab
\ooo Octal number of one to three digits
\xhh . . . Hexadecimal number of one or more digits

Flow chart
To demonstrate flowchart techniques, take another look at the AC algorithm used in the
previous section.
if temperature >= 80
Turn AC on
else
Turn AC off
end if
This AC algorithm can also be easily represented using flowchart techniques, as shown in
Figure 3.2. The flowchart in Figure 3.2 uses a decision symbol to illustrate an expression. If the expression
evaluates to true, program flow moves to the right, processes a statement, and then terminates.
If the expression evaluates to false, program flow moves to the left, processes a
different statement, and then terminates.
As a general rule of thumb, your flowchart’s decision symbols should always move to the right
when an expression evaluates to true. However, there are times when you will not care if an
expression evaluates to false. For example, take a look at the following algorithm implemented
in pseudo code.
if target hit == true
Incrementing player’s score
end if
In the preceding pseudo code, I’m only concerned about incrementing the player’s score when
a target has been hit. I could demonstrate the same algorithm using a flowchart, as shown
in Figure 3.3.
Example
if action == deposit
Deposit funds into account
else
if balance < withdraw amount
insufficient funds for transaction
else
Withdraw monies
end if
end if

INTRODUCTION TO BOOLEAN ALGEBRA


Boole developed his own branch of logic containing the values true and false and the operators
and, or, and not to manipulate the values.

and Operator truth table


x y Result
true true true
true false false
false true false
false false false

or Operator truth table


x y Result
true true true
true false true
false true true
false false false

not Operator truth table


x Result
true false
false true

COMMON CHARACT ER SETS USED TO IMPLEMENT


COMMON CHARACT ER SETS USED TO IMPLEMENT COMPOUND CONDITIONS
Character Set Boolean Operator
&& and
|| or

COMMON LIBRARY FUNCTIONS


Library Name Function Name Description
Standard input/output scanf() Reads data from the keyboard
Standard input/output printf() Prints data to the computer monitor
Character handling isdigit() Tests for decimal digit characters
Character handling islower() Tests for lowercase letters
Character handling isupper() Tests for uppercase letters
Character handling tolower() Converts character to lowercase
Character handling toupper() Converts character to uppercase
Mathematics exp() Computes the exponential
Mathematics pow() Computes a number raised to a power
Mathematics sqrt() Computes the square root

1.17.1. Arithmetic Operators:


Operation Symbol Meaning
Add +
Subtract -
Multiply *
Division / Remainder lost
Modulus %
Gives the remainder on integer division, so
7 % 3 is 1.
-- Decrement
++ Increment
1.17.2. Relational Operators:
The relational operators are used to determine the relationship of one quantity to
another. They always return 1 or 0 depending upon the outcome of the test. The
relational operators are as follows:
Operator Action
= = equal to
! = not equal to
< Less than
<= less than or equal to
> Greater than
>= Greater than or equal to
To test for equality is ==
If the values of x and y, are 1 and 2 respectively then the various expressions and their
results are:
Expression Result Value
X != 2 False 0
X == 2 False 0
X == 1 True 1
Y != 3 True 1
A warning: Beware of using “='' instead of “= ='', such as writing accidentally
if (i = j) .....
This is a perfectly LEGAL C statement (syntactically speaking) which copies the value in
"j" into "i", and delivers this value, which will then be interpreted as TRUE if j is nonzero.
This is called assignment by value -- a key feature of C.
Not equals is: !=
Other operators < (less than), > (grater than), <= (less than or equals), >= (greater
than or equals) are as usual.
1.17.3. Logical (Comparison) Operators:
Logical operators are usually used with conditional statements. The three basic logical
operators are && for logical AND, || for logical OR and ! for not.
The truth table for the logical operators is shown here using one’s and zero’s. (the idea
of true and false under lies the concepts of relational and logical operators). In C true is
any value other than zero, false is zero. Expressions that use relational or logical
operators return zero for false and one for true.
P Q P && q P || q ! p
00001
01011
11110
10010
1.17.4. Bit wise Operators:
The bit wise operators of C are summarised in the following table:
Bitwise operators
& AND
| OR
^ XOR
~ One's Compliment
<< Left shift
>> Right Shift

1.17.5. Conditional Operator:


Conditional expression use the operator symbols question mark (?)
(x > 7) ? 2 : 3
What this says is that if x is greater than 7 then the expression value is 2. Otherwise the
expression value is 3.
In general, the format of a conditional expression is:
a?b:c
Where, a, b & c can be any C expressions.
Evaluation of this expression begins with the evaluation of the sub-expression ‘a’. If the
value of ‘a’ is true then the while condition expression evaluates to the value of the
subexpression
‘b’. If the value of ‘a’ is FALSE then the conditional expression returns the
value of the sub-expression ‘C’.
1.18. sizeof Operator:
In situation where you need to incorporate the size of some object into an expression
and also for the code to be portable across different machines the size of unary operator
will be useful. The size of operator computes the size of any object at compile time. This
can be used for dynamic memory allocation.
Usage: sizeof (object)
The object itself can be the name of any sort of variable or the name of a basic type (like
int, float, char etc).
Example:
sizeof (char) = 1
sizeof (int) = 2
sizeof (float) = 4
sizeof (double) = 8
1.19. Special Operators:
Some of the special operators used in C are listed below. These are reffered as
separators or punctuators.
Ampersand (&) Comma ( , ) Asterick ( * )
Ellipsis ( … ) Braces ( { } ) Hash ( # )
Brackets ( [ ] ) Parenthesis ( () ) Colon ( : )
Semicolon ( ; )
Ampersand:
Ampersand ( & ) also referred as address of operator usually precedes the identifier
name, which indicates the memory allocation (address) of the identifier.
Comma:
Comma ( , ) operator is used to link the related expressions together. Comma used
expressions are linked from left to right and the value of the right most expression is the
value of the combined expression. The comma operator has the lowest precedence of all
operators. For example:
Study material
20
Sum = (x = 12, y = 8, x + y);
The result will be sum = 20.
The comma operator is also used to separate variables during declaration. For example:
int a, b, c;
Asterick:
Asterick ( * ) also referred as an indirection operator usually precedes the identifier
name, which identifies the creation of the pointer operator. It is also used as an unary
operator.
Ellipsis:
Ellipsis ( … ) are three successive periods with no white space in between them. It is
used in function prototypes to indicate that this function can have any number of
arguments with varying types. For example:
void fun (char c, int n, float f, . . . . )
The above declaration indicates that fun () is a function that takes at least three
arguments, a char, an int and a float in the order specified, but can have any number of
additional arguments of any type.
Hash:
Hash (#) also referred as pound sign is used to indicate preprocessor directives, which is
discussed in detail already.
Parenthesis:
Parenthesis () also referred as function call operator is used to indicate the opening and
closing of function prototypes, function calls, function parameters, etc., Parenthesis are
also used to group expressions, and there by changing the order of evaluation of
expressions.
Semicolon:
Semicolon (;) is a statement terminator. It is used to end a C statement. All valid C
statements must end with a semicolon, which the C compiler interprets as the end of the
statement. For example:
c=a+
Order of Precedence of C Operators:
Highest ( ) [ ] -> .
! ~ - (type) * & sizeof ++ --
*/ %
+-
<< >>
< <= >= >
== !=
&
^
|
&&
||
?:
= += -= *= /= etc.
Lowest , (comma)

Reading writing of strings


Function Operation
getchar() Reads a character from the keyboard and waits for carriage return
getche() Reads a character with echo and does not waits for carriage return
getch()
Reads a character from the keyboard with out echo and not waits for
carriage return
Putchar() Writes a character to the screen
gets() Reads a string from the keyboard
puts() Writes a string to the screen

Conversion Specifiers:

Specifier Data Type


%c char
%f float
%d or %i signed int (decimal)
%h short int
%p Pointer (Address)
%s Stringof Characters
Qualified Data Types
%lf long float or double
%o unsigned int (octal)
%u unsigned int (decimal)
%x unsigned int (hexadecimal)
%X Unsigned Hexadecimal (Upper Case)
%e Scientific Notation (Lower case e)
%E Scientific Notation (Upper case E)
%g Uses %e or %f which ever is shorter
%ho short unsigned int (octal)
%hu short unsigned int (decimal)
%hx short unsigned int (hexadecimal)
%lo long unsigned int (octal)
%lu long unsigned int (decimal)
%lx long unsigned int (hexadecimal)
%Lf long double
%n
The associated argument is an integer pointer into
which the number of characters written so far is placed.
%% Prints a % sign

Distinguishing between printf() and puts() functions:


puts() printf()
They can display only one string at a time.
They can display any number of
characters, integers or strings a time.
All data types of considered as characters. Each data type is considered
separately depending upon

The format specifiers for scanf () are as follows


Code Meaning
%c Read a single character
%d Read a decimal integer
%i Read a decimal integer, hexa decimal or octal integer
%h Read a short integer
%e Read a floating-point number
%f Read a floating-point number
%g Read a floating-point number
%o Read an octal number
%s Read a string
%x Read a hexadecimal number
%p Read a pointer
%n Receives an integer value equal to the number of characters read so far
%u Read an unsigned integer
%[..] Scan for a string of words

scanf() gets()
Strings with spaces cannot be accessed
until ENTER key is pressed.
Strings with any number of spaces can
be accessed.
All data types can be accessed.
Only character data type can be
accessed.
Spaces and tabs are not acceptable as a
part of the input string.
Spaces and tabs are perfectly acceptable
of the input string as a part.
Any number of characters, integers.
Only one string can be received at a
time. Strings, floats can be received at a
time.

Key Terms & Concepts


The list of terms below is provided to supplement or elaborate on the boldfaced terms
and definitions provided in the course textbook. Students are advised to also review the
textbook to develop a fuller understanding of these and other important terms related.
Text is a form of data consisting of characters such as letters, numerals, and
punctuation.
ASCII is the American Standard Code for Information Interchange; a language for
representing text on computers.
Binary is a word with two meanings in programming. The first and most common
meaning relates to the numbering system known as "Base-2" in which all values are
represented using only "two (bi) numerals (nary) ". The second meaning relates to the
use of operators such as the minus sign (-) in a formula. When the symbol appears
between two items (such as the values 5 and 2 in the formula 5-2), it is referred to as a
"binary operator". When the symbol appears preceding only one item (such as the value
2 in the formula -2), it is referred to as a "unary operator".
Bits are binary digits (0 or 1) that represent the settings of individual switches or
circuits inside a computer (OFF or ON). Data is represented as standardized patterns of
bits.
A byte is the unit of measure of storage space used to represent a single character.
There are typically 8 bits in a byte.
Decimal is another word with two meanings in programming. The first and most
common meaning relates to the numbering system known as "Base-10" in which all
values are represented using ten digits (0-9). The second meaning relates to the use of
a decimal point when writing numbers with fractional parts, such as one half in 8.5 or
one tenth in 4.1. Numbers written containing a decimal point are often referred to as
"decimal numbers", however this is technically incorrect, as it implies that the numbers
are also written using the Base-10 numbering system (which may not be the case). A
more precise way to talk about numbers that contain fractional parts is to call them
"floating point numbers" or more simply "floats".
Bug: A bug is an error in a program. These can be split into syntax errors and semantic
errors. A Syntax error is where the language rules of the C programming language have
been broken, and can be easily picked up by the C Compiler – e.g. a missing semi-colon.
A semantic error is harder-to find, and refers to an error where the syntax of the
program is correct, but the meaning of the program is not what was intended – e.g. int
three_cubed=3*3; when you actually meant int three_cubed=3*3*3;
Study material
31
Breakpoint: This is a line of source code, marked in some way, where the program
execution stops temporarily for you to examine what is happening – e.g. the contents of
variables etc. Once stopped, you can usually step through the execution of the program
line-by-line to see how variables change, and to follow the flow of execution in the
program.
Build: This is the step following compilation. It takes one or a number of object code
files generated by one or more compiled programs, and links them together to form an
executable file that comprises instructions that are understood by the computer on which
the application is to run.
Execution: This means running a program – i.e. starting the executable file going so
that we can see the program working.
Debugging: Debugging refers to the task of removing bugs from a program. This is
often attained with the help of tools in the IDE, such as creating breakpoints, stepping
through line-by-line etc.
Executable: The name given to a file on your computer that contains instructions
written in machine code. These are typically applications that do some task on your
computer – e.g. Microsoft Word has an executable file (winword.exe) that you can
execute in order to start the application.
IDE: Integrated Development Environment. The application used to edit your source
code, perform debugging tasks, compile and build your application, and organize your
projects. It acts as a complete set of tools in which to create your C programs.
Program: This is a generic name for an application on your computer that performs a
task. An application such as Microsoft Word may be referred to as a program.
Sometimes also used to refer rather vaguely as the source code that, when compiled,
will generate the executable application.
Run: When we refer to running a program, we are referring to the execution (starting)
of the executable version of the program so that we can see the program working.
Machine Code: The language that each type of computer understands. All PCs
understand instructions based on microprocessors such as the Intel 8086 through to the
latest Pentium processors, Macintoshes understand instructions based on the 68000 and
upwards processors, and Sun servers understand instructions based on Sun's Sparc
processor.
Syntax: The syntax refers to the structure of a C program. It refers to the rules that
determine what is a correct C program. A Syntax Error is where a part of the program
breaks these rules in some way – e.g. a semi-colon omitted from the end of a C
instruction.
A compiler is a program that translates high-level language (such as C) instructions into
machine language instructions. It also often provides an editor for writing the program
code in the first place. Compilers often are packaged with other software known as
programming environments that include features for testing and debugging programs.
Source Code: The C Program that you type in using a text editor, containing a list of C
instructions that describe the tasks you wish to perform. The source code is typically
fairly independent of the computer that you write it on – the compile and build stages
convert it to a form that is understood by your computer.
Study material
32
Object code is machine language that resulted from a compiling operation being
performed. Files containing C object code typically end with a filename extension of
".obj".
Text Editor: An application program, rather like a word-processor, that you use to type
out your C source code instructions to create a C program. These can be as simple as
the notepad text editor supplied with Microsoft Windows, to the sophisticated editor that
comes part of an IDE, typically including features such as bookmarks, integrated
debugging, and syntax highlighting.
A header file is a file containing useful blocks of pre-written C source code that can be
added to your source code using the "# include" compiler directive. Header files typically
end with a filename extension of ".h".
White space is any character or group of characters that a program normally interprets
as a separator of text, including: spaces ( ), form feeds (\f), new-lines (\n), carriage
returns (\r), horizontal tabs (\t), and vertical tabs (\v). In C source code, all of these
characters are interpreted as the same unless they are quoted. In other words, one
space is interpreted the same as three blank lines.
The declaration part of a program defines its identifiers, such as: symbolic constants
and variable names and data types.
The body of a program contains the statements that represent the steps in the main
algorithm.
A constant (also called as literal) is an actual piece of data (also often referred to as a
"value") such as the number 5 or the character 'A'.
Symbolic Constants are aliases (nicknames) used when coding programs in place of
values that are expected to be the same during each execution of a program, but might
need to be changed someday. Symbolic constants are defined within C source code using
the "#define" compiler directive at the top of the program to allow easy location and
revision later.
Variable: A temporary storage location in a C program, used to hold data for
calculations (or other uses) further in on in the program. For identification purposes, a
variable is given a name, and to ensure we hold the right sort of information in the
variable, we give it a type (e.g. int for whole numbers, float for decimal numbers). An
example would be int count, total; or char name[21]; or float wage_cost,
total_pay;
A keyword is a reserved word within a program that can NOT be redefined by the
programmer.
Identifiers are labels used to represent such items such as: constants, variables, and
functions. Identifiers are case-sensitive in C, meaning that upper and lowercase
appearances of the same name are treated as being different identifiers. Identifiers that
are defined within a function (see below) are local to that function, meaning that they
will not be recognized outside of it. Identifiers that are defined outside of all functions
are global, meaning that they will be recognized within all functions.
Addresses are numeric designations (like the numbers on mailboxes) that distinguish
one data storage location from another. Prior to the use of identifiers, programmers had
to remember the address of stored data rather than its identifier. In C, addresses are
referred to by preceding an identifier with an ampersand symbol (&) as in &X which
refers to the address of storage location X as opposed to its contents.
Study material
33
Integer data is a numeric type of data involving a whole number (i.e. it CANNOT HAVE
a fractional portion). An example of an integer constant is 5 (written without a decimal
point). The most common type identifier (reserved word used in a declaration) for
integer data is int.
Floating point data is a numeric type of data that CAN HAVE a fractional portion.
Mathematicians call such data a real number. An example of a floating point constant is
12.567 (written without a decimal point). The most common type identifiers for floating
point data are float (for typical numbers) and double (for numbers such as
1.2345678901234E+205 that involve extreme precision or magnitude).
Character data is a type of data that involves only a single symbol such as: 'A', '4', '!', or
' ' (a blank space). The type identifier for character data is char.
String data is a type of data involving multiple symbols such as words or sentences.
The C language stores strings as a collection of separate characters (see above).
Boolean data is a logical type of data involving only two values: True or False. The
identifier used in C to declare Boolean data is bool.
A problem statement is program documentation that defines the purpose and
restrictions of a program in sufficient detail that the program can be analyzed and
designed without more facts.
A sample softcopy is program documentation that precisely demonstrates all video (or
other intangible) output required of a program.
A sample hardcopy is program documentation that precisely demonstrates all printed
(tangible) output required of a program.
A structure diagram is graphic documentation that helps to describe the hierarchical
relationship between a module and its various sub-modules.
An algorithm is a finite list of steps to follow in solving a well-defined task, written in
the language of the user (i.e. in human terms).
Pseudocode is an algorithm written in English, but as clearly stated logical items that
can be easily translated by a programmer into C or other high-level programming
languages.
A desk check is a manual test of a program algorithm that is performed prior to writing
the source code. It must follow the algorithm exactly and typically produces two items of
documentation: the tracing chart showing what values are stored in memory during
program execution, and any test outputs (softcopy and hardcopy) showing that the
algorithm will produce the output specified earlier in the samples.
A logic error is caused by a mistake in the steps used to design the program algorithm.
A syntax error is caused by a grammatical error in the language of the source code.
A run-time error occurs when a program encounters commands it cannot execute.
Comments can be included within C source code, enclosed in the symbols /* and */.
The inclusion of comments in source code neither causes the program to run more
slowly, nor causes the object code to take up more space, since comments are not
translated.
Study material
34
Blank spaces in C code act as separators and are not allowed in an identifier. Multiple
blank spaces are treated the same as one, except in string constants (text inside of
double quotes).
Character constants must be enclosed in single quote marks (').
String constants must be enclosed in double quote marks (").
Escape sequences are special strings typed within C output statements to produce
characters that would otherwise be interpreted as having special meaning to the
compiler.
Semicolon (;) Each statement is C is normally terminated with a semi-colon ( ; ) except
for: include statements.
A compiler directive (or preprocessor directive) is an instruction in a C source code file
that is used to give commands to the compiler about how the compilation should be
performed (as distinguished from C language statements that will be translated into
machine code). Compiler directives are not statements, therefore they are not
terminated with semi-colons. Compiler directives are written starting with a # symbol
immediately in front of (touching) the command word, such as
#include <stdio.h>
include is a compiler directive in C that is used to indicate that a unit of pre-defined
program code (such as the header file stdio.h) should be linked to your program when it
is compiled.
define is a compiler directive in C that is used to indicate that a symbolic constant is
being used in your program in place of a constant value and that the value should be
used in place of the symbolic constant when translating the source code into machine
language.
{ (open brace) is the symbol used in C to start a group of executable statements.
} (close brace) is the symbol used in C to end a group of executable statements.
printf is the name of a function in C that will display formatted output on the screen.
scanf is the name of a function in C that will store input from a keyboard into a variable
and then advance the cursor to the next line when the user presses the Enter key.
Assignment is the action of storing a value in a memory location and is accomplished
using the symbol =.
An expression is another name for a formula. Expressions consist of operands (such as
constants or variables) and operators (such as + or -). Operators that involve data from
only one operand are called unary operators. In the statement X = -5; the minus sign
acts as a unary operator and operates on a single operand (the constant 5). Operators
that involve data from two operands are called binary operators. In the statement X =
A/B; the slash acts as a binary operator and operates on a pair of operands (the
variables A and B).
An arithmetic expression is one which uses numeric operands (such as constants or
variables) and mathematical operations (such as addition, subtraction, multiplication, or
division) to produce a numeric result. An example of an arithmetic expression is X+3.
Study material
35
Order of Precedence is a term used to describe which operations precede others when
groups of operators appear in an expression. For example, C compilers see the
expression A+B/C as A+(B/C) as opposed to (A+B)/C. The division operation will
preceed the addition because division has a higher order of precedence.
Casting is the process of converting data from one data type to another. For example, if
you try to divide two integer variables A and B and store the result in a floating point
variable C, the result will have any decimal fraction truncated (chopped-off) because
both operands are integers. To prevent this, cast either of the operands as floats before
the division operation is performed, as in either of the following examples:
C = (float) A / B;
C = A / (float) B;
Trying to cast the result instead of the operands would be pointless because the
truncation would have already taken place. So it would be ineffective to try:
C = (float) (A / B);
Top-Down Design is an analysis method in which a major task is sub-divided into
smaller, more manageable, tasks called functions (see definition below). Each sub-task
is then treated as a completely new analysis project. These sub-tasks may be sufficiently
large and complex that they also require sub-division, and so on. The document that
analysts use to represent their thinking related to this activity is referred to as a
structure diagram. For more information and an example of such a diagram, see the web
notes on Analysis & coding of a task involving multiple functions.
Boolean data is a logical type of data with only two values: True and False. Boolean
data can be represented in two ways in C. When you want to store Boolean data for
fututre use, a variable can be declared to have data type of _Bool (notice the leading
underscore and capitalization). A common alternative approach is to represent the true
and false values using the integer values of 1 for true and 0 for false. Many functions in
C use the latter approach and return a 1 or a 0 to indicate if a condition is true or false.
In C, any non-zero integer value is interpreted as true.
Ordinal data is a type of data in which all of the values within the set are known and in
a predictable order. Ordinal data types include: all integer data types and char data, but
not floating point or string data.
Relational operators are those used to evaluate the relationships between items of
data, including:
== for Equal to, the opposite of which is written in C as != (or not equal to).
> - Greater than, the opposite of which is written in C as <= (less than or equal to).
< - Less than, the opposite of which is written in C as >= (greater than or equal to).
Relational expressions (also known as relational tests) describe conditions using
formulae such as X==A+B that compare items of data (possibly including constants,
symbolic constants, variables or arithmetic expressions) and produce a boolean (true or
false) result.
Logical operators such as && for "and", || for "or" and ! for "not" are those used to
combine conditions into logical expressions such as (X==0 && Y>10) to produce a single
boolean result.
A condition is any expression that produces a boolean result.
Branching is the act of breaking out of the normal sequence of steps in an algorithm to
allow an alternative process to be performed or to allow the repetition of process(es).

Control statements:
1. Un-conditional:
• goto
• break
• return
• continue
2. Conditional:
• if
• if – else
• Nested if
• switch case statement
3. Loop or iterative:
• for loop
• while loop
• do-while loop

You might also like