Вы находитесь на странице: 1из 17

I) Storage Classes

Four Storage Classes

 Automatic
 Register
 Static
 External

Automatic Storage Class:


Represented by keyboard ‘auto’.
auto int sum;
When a variable is declared as ‘auto’, it is created on
computer’s memory.
Register Storage Class:
Its same as automatic storage class, except that the variable is
not stored on computer’s memory. The register value is stored on
the CPU registers.
register int num;
Here, ‘num’ is the variable which is declared as belonging to
‘register’ storage class.
Register Variable will be accessed faster than any other variable
since it stays within the CPU & available to the processor
immediately.
Static Storage Class:
AV & RV will not be available outside the block since they are
deleted immediately when coming out of the block. SV also will
not be available out of the block, but they are not deleted.
static int i;
static float x;
External Storage Class:
The variable auto, register & static are all variable inside a
block where they are declared. So their scope is ‘local’, But a
variable which belong to external storage class will have
‘global’ scope and hence will be available to all the functions.
extern int x;

II) Program to Print ASCII Value

#include <stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c", &c);
printf("ASCII value of %c = %d", c, c);
return 0;
}

# ASCII value of 'A' is 65.


Z = 90 a = 97 z = 122

III) Variable & Rules for declaring Variable

Variables are simply names used to refer to some location in


memory – a location that holds a value with which we are
working.
 Every variable name should start with alphabets or
underscore (_).
 No spaces are allowed in variable declaration.
 Except underscore (_) no other special symbol are allowed
in the middle of the variable declaration.
 Maximum length of variable is 8 characters depend on
compiler and operation system.
 Every variable name always should exist in the left hand
side of assignment operator.
 No keyword should access variable name.
IV) Datatypes in C

 Primary Data Type – char, int, float, double, void


 Secondary Data Type – Array, Pointer, Structure, Union,
Enumeration

PRIMARY DATA TYPES :

 int - integer: a whole number


 float - floating point value: ie a number with a fractional part.
 double - a double-precision floating point value.
 char - a single character.
 void – empty data type

DATA TYPE RANGE MEMORY FORMAT USED


IN BYTES IN PRINTF()

int -32768 to 32767 2 %u


short unsigned int 0 to 65535 2 %u
long int -2147483648 to +2147483648 4 %lu
long unsigned int 0 to 42944967295 4 %f
float -3.4e38 to +3.4e38 4 %lf
Double -1.7e308 to +1.7e308 8 %Lf
Long double -1.7e4932 to +1.7e4932 10 %c
Char -128 to 127 1 %c
Unsigned char 0 to 255 1 %s
V) String Manipulations In C Programming Using Library Functions

standard library "string.h".


Function Work of Function
strlen() Calculates the length of string
strcpy() Copies a string to another
string

strcat() Concatenates(joins) two strings


strcmp() Compares two string
strlwr() Converts string to lowercase
strupr() Converts string to uppercase

VI) IDENTIFIERS

 Identifiers are names for entities in a C program, such


as variables, arrays, functions, structures, unions and
labels. An identifier can be composed only of uppercase,
lowercase letters, underscore and digits, but should
start only with an alphabet or an underscore.
 If the identifier is not used in an external link
process, then it is called as internal. Example: Local
variable.
 If the identifier is used in an external link process,
then it is called as external. Example: Global variable

Rules for constructing identifiers

 The first character in an identifier must be an alphabet


or an underscore and can be followed only by any number
alphabets, or digits or underscores.
 They must not begin with a digit.
 Uppercase and lowercase letters are distinct. That is,
identifiers are case sensitive.
 Commas or blank spaces are not allowed within an
identifier.
 Keywords cannot be used as an identifier.
 Identifiers should not be of length more than 31
characters.
 Identifiers must be meaningful, short, quickly and easily
typed and easily read.

Valid identifiers: total


Sum
average
_x
y_
mark_1
x1

Invalid identifiers: (REASON)


1x - begins with a digit
char - reserved word
x+y - special character

VII) Operators in C Language

C operators can be classified into following types:

 Arithmetic operators
 Relational operators
 Logical operators
 Bitwise operators
 Assignment operators
 Conditional operators
 Special operators
Arithmetic operators
Operator Description

+ adds two operands

- subtract second operands from first

* multiply two operand

/ divide numerator by denominator

% remainder of division

++ Increment operator - increases integer value by one

-- Decrement operator - decreases integer value by one

Relational operators
Operator Description

== Check if two operand are equal

!= Check if two operand are not equal.

> Check if operand on the left is greater than operand on the right

< Check operand on the left is smaller than right operand

>= check left operand is greater than or equal to right operand

<= Check if operand on left is smaller than or equal to right operand


Logical operators
Operator Description Example

&& Logical AND (a && b) is false

|| Logical OR (a || b) is true

! Logical NOT (!a) is false

Bitwise operators
Bitwise operators perform manipulations of data at bit level. These
operators also perform shifting of bits from right to left.
Operator Description

& Bitwise AND

| Bitwise OR

^ Bitwise exclusive OR

<< left shift

>> right shift

Assignment Operators

Operator Description Example

= assigns values from right side operands to left a=b


side operand

+= adds right operand to the left operand and assign a+=b is same
the result to left as a=a+b

-= subtracts right operand from the left operand and a-=b is same
assign the result to left operand as a=a-b
*= multiply left operand with the right operand and a*=b is same
assign the result to left operand as a=a*b

/= divides left operand with the right operand and a/=b is same
assign the result to left operand as a=a/b

%= calculate modulus using two operands and assign a%=b is same


the result to left operand as a=a%b

Conditional operator

The syntax of a conditional operator is :


expression 1 ? expression 2: expression 3

Special operator
Operator Description Example

sizeof Returns the size of an sizeof(x) return size of the


variable variable x

& Returns the address of an &x ; return address of the


variable variable x

* Pointer to a variable *x ; will be pointer to a


variable x

VIII) ALGOITHUM AND CHARACTERISTICS AND FLOWCHARTS

An algorithm is a step by step method of solving a problem.

The characteristics of a good algorithm are:

 Precision – the steps are precisely stated(defined).


 Uniqueness – results of each step are uniquely defined and only
depend on the input and the result of the preceding steps.
 Finiteness – the algorithm stops after a finite number of
instructions are executed.
 Input – the algorithm receives input.
 Output – the algorithm produces output.
 Generality – the algorithm applies to a set of inputs.

FLOWCHART
A flowchart is the graphical or pictorial representation of
algorithm with the help of different symbols, shapes and arrows in
order to demonstrate a process or a program. With algorithms, we can
easily understand a program. The main purpose of a flowchart is to
analyze different processes. Several standard graphics are applied
in a flowchart:

 Terminal Box - Start / End

 Input / Output

 Process / Instruction

 Decision

 Connector / Arrow
IX) HISTORY OF C

The Beginnings of C

Developing C was not originally the objective of its founders. In


fact, various circumstances and problems created the ideal
situation for its creation. In the 1960s, Dennis Ritchie, who was
an employee of Bell Labs (AT&T), along with some of his
colleagues, had been working on developing an operating system
which could be used by many users simultaneously. This operating
system was known as Multics, and it was meant to allow many users
to share common computing resources. Multics offered many
benefits, but also had many problems.

Evolution of C

Over time, C began to be used in personal computers for


developing software applications and other purposes.The first
change (even if only a little) came when the American National
Standards Institute (ANSI) formed a committee in 1983 to
standardize C. After a review of the language, they modified it a
little so that it was also compatible with other programs that
preceded C. So the new ANSI standard came into being in 1989, and
is known as ANSI C or C89. The International Organization for
Standardization (ISO) has also contributed to the standardization
of C.Over time, C has evolved as it has added some significant
features like memory management, functions, classes and libraries
to its rich feature set.

X) TOKENS

The basic and smallest unit of a C program is called C tokens.

There are six types of token in C.

 Keywords: Keywords are special words that are used to give a


special meaning to the program and can’t be used as variable and
constant. They are basically a sequence of characters that have
fixed to mean for example break, for, while, do-while, do, if,
int, long, char.
 Identifiers: Identifiers are the sequence of alphabets and digit,
but keyword should not be used as an identifier.
 Constants: The quantity which does not change during the
execution of a program is known as constant.
 Variables: Variables are used to give the name and allocate
memory space
 String: String is a collection of more than one character
 Operators: Operators acts as connectors and they indicate what
type of operation is being carried out. The values that can be
operated by these operators are called operands. They are used to
perform basic operations, comparison, manipulation of bits and so
on.

PROGRAMMING CODE

I) C program to perform addition, subtraction, multiplication and


division

#include <stdio.h>

int main()

int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

scanf("%d%d", &first, &second);

add = first + second;

subtract = first - second;

multiply = first * second;

divide = first / second;

printf("Sum = %d\n", add);

printf("Difference = %d\n", subtract);

printf("Multiplication = %d\n", multiply);

printf("Division = %.2f\n", divide);


return 0;

II) C Program to Calculate the Area of a Triangle

#include <stdio.h>

#include <math.h>

void main()

int s, a, b, c, area;

printf("Enter the values of a, b and c \n");

scanf("%d %d %d", &a, &b, &c);

s = (a + b + c) / 2;

area = sqrt(s * (s - a) * (s - b) * (s - c));

printf("Area of a triangle = %d \n", area);

III) C program to find reverse of a number

#include <stdio.h>

int main()

int n, reverse = 0;

printf("Enter a number to reverse\n");


scanf("%d", &n);

while (n != 0)

reverse = reverse * 10;

reverse = reverse + n%10;

n = n/10;

printf("Reverse of entered number is = %d\n", reverse);

return 0;

IV) Fibonacci series C program using for loop

int main()

int n, first = 0, second = 1, next, c;

printf("Enter the number of terms\n");

scanf("%d", &n);

printf("First %d terms of Fibonacci series are:\n", n);

for (c = 0; c < n; c++)

if (c <= 1)

next = c;
else

next = first + second;

first = second;

second = next;

printf("%d\n", next);

return 0;

V) Factorial of a Number

#include <stdio.h>

int main()

int n, i;

unsigned long long factorial = 1;

printf("Enter an integer: ");

scanf("%d",&n);

if (n < 0)

printf("Error! Factorial of a negative number doesn't exist.");

else

for(i=1; i<=n; ++i)


{

factorial *= i; // factorial = factorial*i;

printf("Factorial of %d = %llu", n, factorial);

return 0;

VI) C program to find area of a rectangle

#include <stdio.h>

int main()

float l,b,area;

printf("Enter the value of length: ");

scanf("%f",&l);

printf("Enter the value of breadth: ");

scanf("%f",&b);

area=l*b;

printf("Area of rectangle: %f\n",area);

return 0;

}
VII) Program to Check Prime Number

#include <stdio.h>

int main()

{ int n, i, flag = 0;

printf("Enter a positive integer: ");

scanf("%d",&n);

for(i=2; i<=n/2; ++i)

// condition for nonprime number

if(n%i==0)

flag=1;

break;

if (flag==0)

printf("%d is a prime number.",n);

else

printf("%d is not a prime number.",n);

return 0;

}
VIII) ODD OR EVEN

#include <stdio.h>

int main()

int number;

printf("Enter an integer: ");

scanf("%d", &number);

// True if the number is perfectly divisible by 2

if(number % 2 == 0)

printf("%d is even.", number);

else

printf("%d is odd.", number);

return 0;

Вам также может понравиться