Instructor Led C Online Webinar Session - 1 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

C

WEBINAR
COACHING
BY APTUTS.COM
EMAIL: LEARN@APTUTS.COM

ABOUT ME
Bachelor's Degree in Computer Science Engineering
Software Engineer in IT Industry & Teaching Experience
7 Years of IT experience in various technologies
Expertise in C, C++, Application Development, Manual Testing, Web Automation Testing, Mobile
Automation Testing, Website Designing, PHP and VBScript
Founder of LearnCOnline.com, LearnCPPOnline.com and Aptuts.com
Contact Info: prashant@aptuts.com

COURSE CURRICULUM
Following topics would be covered:
Overview
Fundamentals and Control Statements
Data Input and Output in C
Functions and Function Overloading

Arrays, Structures and Pointers


Strings and String handling functions
Storage Classes in C
Introduction to File Operations in C

The C Pre-processor Directives

OVERVIEW
C is a programming language developed by AT & Ts Bell Laboratories of USA in 1972. It was designed and written
by a man named Dennis Ritchie. C is reliable, simple and easy to use. C has survived for more than 4 decades.
Before starting with the programming, lets have a look at the C Character set.
Any alphabet, digit or special symbol can be termed as a character. Below are the list of valid alphabets, digits and
symbols allowed in C.
Alphabets:

A, B, C, D, ,X,Y, Z
a, b, c, d, ,x, y, z
Digits :
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special Symbols :
~ ! @ # % ^ &amp; * ( ) _ - + = | \ { } [ ] : ; " ' < > , . ? /

COMMENTS STATEMENTS
C supports two types of comments., // and /*...*/
Here, everything following // till the end of line is treated as comment.
Usually /*..*/ style is used for commenting out of a block code, whereas, // is used for singleline comments.
Example of single-line comment:
// This is a single line comment
Example of multiple-line comment:
/*This is
a multiple line comment*/

IDENTIFIERS AND KEYWORDS


In a C program, every word is either classified as an identifier or a keyword
Identifiers, as the name suggests, are used to identify or name various program
elements such as variables, constants, functions etc.
On the other hand, Keywords are a kind of reserved word which have standard,
predefined meanings in C

IDENTIFIERS
As stated before, identifiers are names that are given to various program elements such as variables,
constants, functions, arrays etc. There are certain rules regarding identifier names in C, as stated
below:
1.

Identifiers must consist of letters and digits, in any order, except that the first character must be a
letter

2.

Both upper-case and lower-case letters are permitted

3.

The underscore character (_) can also be included, and is considered to be a letter

4.

An identifier should contain enough characters so that its meaning is readily apparent

5.

There are certain reserved words, called keywords, that have standard, predefined meanings in C.
These keywords can be used only for their intended purpose. They cannot be used as a
programmer-defined identifiers

6.

It is required to note here that the keywords are all lower-case. Since upper-case and lower-case
characters are not equivalent, it is possible to utilize an upper-case keyword as an identifier

EXAMPLES OF IDENTIFIERS
Examples of valid identifiers:
z
x11
sum_1
_temperature
names
area
Examples of Invalid identifiers:
7th
a
order-no
error flag

KEYWORDS
As stated before, keywords are the words whose meaning has already been explained to the C
compiler (or in a broad sense to the computer).The keywords cannot be used as identifier
names because, if we do so, we are trying to assign a new meaning to the keyword, which is
not allowed by the computer.The keywords are also called Reserved words.
Examples of Keywords in C:

and
or
register
char
int
float

DATA TYPES
Data types supported by C can be broadly divided into six heads as stated follows:
1.

int data-type

2.

char data-type

3.

float data-type

4.

double data-type

5.

bool (boolean) data-type

6.

enum (enumeration) data-type

DATA TYPES
int data-type:
int data-type represents the whole number (i.e., integer) quantities. Integers are required not to contain a decimal point or an
exponent
char data-type:
char data-type is used to represent individual characters. Hence, the char type generally requires only one byte of memory
float data-type:
float data-type (also called as floating point) represents values containing decimal places. A floating point value is distinguished by the
presence of a decimal point. It is permissible to omit digits before the decimal point, or digits after the decimal point, but obviously not
permissible to omit both.

double data-type:
double data-type is very similar to float data-type. It is used whenever the accuracy provided by a float variable is not sufficient.
Variables declared to be of type float can store roughly twice as many significant digits as can a variable of type float can store
bool (boolean) data-type:
This data type can take only two values true or false. It is commonly used to hold the results of comparisons
enum (enumeration) data-type:

An enumeration data type is an integral type that is defined by the user

VARIABLES AND DECLARATIONS


Variables in C:
A variable can be defined as a quantity that varies during program execution.
A variable is a symbol that represents a storage location in the computers memory. The information
that is stored in that location is called the value of the variable.
One common way for a variable to obtain a value is by an assignment. This has the syntax:
variable name = expression
First, the expression is evaluated and then the resulting value is assigned to the variable. The equal
sign = is the assignment operator in C.
Declarations in C:
A declaration associates a group of variables with a specific data-type. All variables must be declared
before they can appear in executable statements. A declaration consists of a data-type, followed by
one or more variable names, ending with a semicolon. E.g., int a = 10;

OPERATORS AND EXPRESSIONS


An operator, in general, is a symbol that operates on a certain data-type. For example, the
operator + is the addition operator. It can operate on integer, character and real (float and double)
numbers.
On the other hand, an expression is a combination of variables, constants and operators
written according to the syntax of the language.
Types of Operators:
1. Arithmetic operators
2. Unary operators
3. Increment and Decrement operators
4. Relational operators
5. Logical operators
6. Assignment operators
7. Conditional operators

ARITHMETIC OPERATORS
There are five arithmetic operators. They are:
1. Addition (+)
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Remainder after integer division (%). The % operator is also sometimes referred to as
the modulus operator.
Example of the use of Arithmetic Operators:
Suppose that the x and y are integer variables whose values are 10 and 3 respectively. Several
arithmetic expressions involving these variables are shown below, together with their resulting
values:
x + y (Value: 13)
x y (Value: 7)

UNARY OPERATORS
C includes a class of operators that act upon a single operand to produce a new value. Such
operators are known as unary operators. Unary operators usually precede their single
operands, through some unary operators are written after their operands.
Perhaps the most common unary operation is unary minus, where a numerical constant, variable
or expression is preceded by a minus sign.
Note that the unary operation is distinctly different from the arithmetic operator which denotes
subtraction (-) as the subtraction operator requires two operands.
Example:
-175, -root1, -(x+y) etc.

INCREMENT AND DECREMENT


These operators also fall under the broad category of unary operators but are quite distinct
than unary minus.
The increment and decrement operators are very useful in C language. They are extensively used
in for and while loops. The syntax of these operators is given below:
++<variable name>
<variable name>++
--<variable name>
<variable name>- The operator ++ adds 1 to the operand and -- subtracts 1 from the operand. These operators
manifest in two forms: prefix and postfix.
For example, the ++ operator can be used in two ways:
++m and m++

RELATIONAL OPERATORS
There are four relational operators. They are:
1.

< (less than)

2.

> (greater than)

3.

<= (less than or equal to)

4.

>= (greater than or equal to)

Closely associated with the above mentioned relational operators are the following two equality
operators:
1.

== (equal to)

2.

!= (not equal to)

RELATIONAL OPERATORS (CONDT)


These six operators are used to form logical expressions, which represent conditions that are
either true or false. The resulting expressions will be of type integer, since true is represented
in C by the integer value 1 and false by the value 0.
Example:
Suppose that a, b and c are integer variables whose values are 1, 2 and 3 respectively. Several
logical expressions involving these variables are shown below:

a < b (True 1)
a == b (False 0)
c!=2 (True 1)

LOGICAL OPERATORS
A logical operator is used to compare or evaluate logical and relational expressions. There are three logical
operators. They are:
Operator

Meaning

&&

Logical AND

||

Logical OR

Logical NOT

An expression involving && or || is sometimes called compound expressions, since the expression involves two
other expressions, that is, each of these operators (&& and ||) takes two expressions, one to the left and
another to the right.
Example of && operator:
a > b && x == 10

The expression on the left is a > b and that on the right is x == 10. The above stated whole expression evaluates
to true (1) only if both the expressions are true (i.e., if a is greater than b and the value of x is equal to 10).

LOGICAL OPERATORS (CONDT)


Example of ! operator:
The ! (NOT) operator takes single expression and evaluates to true (1) if the expression
is false (0), and evaluates to false (0) if the expression is true (1). In other words, it just
reverses the value of the expression.
For example, consider the following expression:
!(x >= y)
The expression after the ! operator is x >= y. The above not expression evaluates to true only
if the value of x is neither greater than nor equal to y (i.e., only if x is less than y)

ASSIGNMENT OPERATORS
There are several different assignment operators. All of them are used to form assignment expressions, which
assign the value of an expression to an identifier.
The most commonly used assignment operator is =. Assignment expressions that make use of this operator are
written in the form:
identifier = expression
where,
identifier generally represents a variable, and
expression represents a constant, a variable or a more complex expression
Example:
a = 3;
x = y;
sum = a + b;
In the above statements, the first assignment expression causes the integer value 3 to assigned to the variable a,
and the second assignment causes the value of variable yto be assigned to x. In the third assignment, result in
the value of the arithmetic expression is assigned to the variable sum i.e., the value of a + b is assigned to sum.

ASSIGNMENT OPERATORS (CONDT)


Remember that the assignment operator = and the equality operator == are distinctly
different. The assignment operator is used to assign a value to an identifier, whereas the equality
operator is used to determine if two expressions have the same value.
Also, C contains the following five additional assignment operators: +=, -=,*=, /= and %=. To see
how they are used, consider the first operator, +=.
The assignment expression:
expression 1 += expression 2
is equivalent to:
expression 1 = expression + expression 2
Similarly, the assignment expression:
expression 1 -= expression 2
is equivalent to:
expression 1 = expression - expression 2

CONDITIONAL OPERATOR
Simple conditional operations can be carried out with the conditional operator (? :). An expression that makes use of
the conditional operator is called a conditional expression. Such an expression can be written in place of the more
traditional if - else statement.

A conditional expression is written in the form:


expression 1 ? expression 2 : expression 3
While evaluating a conditional expression, expression 1 is evaluated first. If expression 1 is true (i.e., if its value is
non-zero), then expression 2 is evaluated and this becomes the value of the conditional expression. However, if
the expression 1 is false (i.e., if its value is zero) then expression 3 is evaluated and this becomes the value of the
conditional expression. Note that only one of the embedded expressions (either expression 2 or expression 3) is
evaluated determining the value of a conditional expression.
Example:
In the conditional expression below, assume that a is an integer variable:
z = (a < 0) ? 0 : 100;
In the above example, the expression (a < 0) is evaluated first. If it is true, the entire conditional expression takes on
the value 0. Otherwise (if the value is not less than 0), the entire conditional expression takes on the value 100.

OUTPUT
Output in C is enabled by the statement printf which is predefined to corresponding to the
standard output stream.
Example of output statement in C:
printf(Welcome to Aptuts.com);
printf(This is a number %d, num);

INPUT
Contrary to printf, to receive input through the keyboard what is used is scanf
Example of using scanf:
scanf(&d, &num);

To enable the use printf and scanf, one needs to include a header file named stdio.h in the first
line of every program, by the statement:
#include <stdio.h>
This header file contains the declaration that are needed by printf & scanf statement Without
this declaration, the compiler won't recognize printf & scanf.

WRITE FIRST PROGRAM IN C


Write a program in C that will accept two integer value from user and store it in a variable
named x and y. It should perform addition of two input values and the results should be stored
in a variable named z. At the end, it should display the result i.e. value of z on the screen.

THANK YOU

Web: www.aptuts.com
Email: learn@aptuts.com
Social: www.facebook.com/aptuts

You might also like