0% found this document useful (0 votes)
119 views

C Program

The document discusses key concepts in the C programming language including its history, character set, identifiers, keywords, variables, constants, escape sequences, operators, pointers, arrays, strings, and examples. It provides definitions and examples for each concept to explain how they work in C. The document appears to serve as teaching material to introduce foundational elements of the C language.

Uploaded by

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

C Program

The document discusses key concepts in the C programming language including its history, character set, identifiers, keywords, variables, constants, escape sequences, operators, pointers, arrays, strings, and examples. It provides definitions and examples for each concept to explain how they work in C. The document appears to serve as teaching material to introduce foundational elements of the C language.

Uploaded by

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

Name- Madhusmita Patra

Year- 2nd Year


Branch- ECE
Roll.no- 09
Redg.no- 1801298185
Place of Internship- Gandhi Institutute For
Technology, BBSR
 History of ‘C’
 Character set of ‘C’
 Identifiers
 Keywords
 Variables
 Constants
 Escape sequence
 Operators
 Pointer, array, string
 Examples
 conclusion
 C was originally developed in the 1970s, by Dennis
Ritchie at Bell Telephone Laboratories, Inc.
 C is a High level , general –purpose structured
programming language. Instructions of C consists of
terms that are very closely same to algebraic
expressions, consisting of certain English keywords
such as if, else, for ,do and while.
 C contains certain additional features that allows it to
be used at a lower level , acting as bridge between
machine language and the high level languages.
 This allows C to be used for system programming as
well as for applications programming.
 C language consist of some characters set, numbers
and some special symbols.
 The character set of C consist of all the alphabets of
English language.
 C consist of:-
1. Alphabets a to z, A to Z
2. Numeric 0,1 to 9
3. Special Symbols {,},[,],?,+,-,*,/,%,!,;, and more
 The words formed from the character set are building
blocks of C and are sometimes known as tokens.
 These tokens represent the individual entity of
language.
 The following different types of token are used in C :-
1) Identifiers 2)Keywords 3)Constants
4) Operators 5)Punctuation Symbols.
 A 'C' program consist of two types of elements:-
user defined and system defined.
 Identifiers is nothing but a name given to these
elements.
 An identifier is a word used by a programmer to
name a variable , function, or label.
 identifiers consist of letters and digits, in any
order, except that the first character or label.
 Identifiers consist of letters and digits if any
order, except that the first character must be
letter.
 Both Upper and lowercase letters can be used.
 Keywords are nothing
but system defined auto double int struct
identifiers.
 Keywords are reserved break else long switch
words of the language.
case enum register typedef
 They have specific
meaning in the
language and cannot be char extern return union
used by the
programmer as variable const float short unsigned
or constant names.
 C is case sensitive, it continue for signed void
means these must be
used as it is. default goto sizeof volatile
 32 Keywords in C
Programming. do if static while
 A variable is nothing but a name given to a storage area that our
programs can manipulate. Each variable in C has a specific type,
which determines the size and layout of the variable's memory; the
range of values that can be stored within that memory; and the set
of operations that can be applied to the variable.
 The name of a variable can be composed of letters, digits, and the
underscore character. It must begin with either a letter or an
underscore. Upper and lowercase letters are distinct because C is
case-sensitive. There are following basic variable types −
Type Description
 char Typically a single octet(one byte). This is an integer
type.
 Int. The most natural size of integer for the machine.
 float A single-precision floating point value.
 double A double-precision floating point value.
 void Represents the absence of type.
 A constant is a value or an identifier whose value
cannot be altered in a program. For example: 1,
2.5
 As mentioned, an identifier also can be defined as
a constant. eg. const double PI = 3.14
 Here, PI is a constant. Basically what it means is
that, PI and 3.14 is same for this program.

Integer constants:-
 A integer constant is a numeric constant
(associated with number) without any fractional or
exponential part.
 There are three types of integer constants in C
programming:
1. decimal constant(base 10)
2. octal constant(base 8)
3. hexadecimal constant(base 16)
 Sometimes, it is necessary to use characters which cannot be
typed or has special meaning in C programming.
For example: newline(enter), tab, question mark etc. In order to
use these characters, escape sequence is used.
 For example: \n is used for newline. The backslash ( \ ) causes
"escape" from the normal way the characters are interpreted by the
compiler.
 Escape Sequences Character
1. \b Backspace
2. \f Form feed
3. \n Newline
4. \r Return
5. \t Horizontal tab
6. \v Vertical tab
7. \\ Backslash
8. \' Single quotation mark
9. \" Double quotation mark
10. \? Question mark
11. \0 Null character
 An operator is a symbol which operates on a
value or a variable. For example: + is an
operator to perform addition.
 C programming has wide range of operators to
perform various operations. For better
understanding of operators, these operators can be
classified as:-
1. Arithmetic Operators
2. Increment and Decrement Operators
3. Assignment Operators
4. Relational Operators
5. Logical Operators
6. Conditional Operators
7. Bitwise Operators
8. Special Operators
 Operator Meaning of Operator
 + addition or unary plus
 - subtraction or unary minus
 * multiplication
 / division
 % remainder after
division( modulo division)
1. C programming has two operators increment
++ and decrement -- to change the value of an
operand (constant or variable) by 1.
2. Increment ++ increases the value by 1
whereas decrement -- decreases the value by 1.
3. These two operators are unary operators,
meaning they only operate on a single operand.
eg. Int. a=10, b=100
++a = 11
--b = 99
 An assignment operator is used for assigning
a value to a variable. The most common
assignment operator is =
 Operator Example Same as
 = a=b a=b
 += a += b a = a+b
 -= a -= b a = a-b
 *= a *= b a = a*b
 /= a /= b a = a/b
 %= a %= b a = a%b
 A relational operator checks the relationship
between two operands. If the relation is true, it
returns 1; if the relation is false, it returns value
0.
 Relational operators are used in decision making
and loops.
Operator Meaning of Operator Example
 == Equal to 5 == 3 returns
0
 > Greater than 5>3
returns 1
 < Less than 5 < 3 returns 0
 != Not equal to 5 != 3
returns 1
 >= Greater than or equal to 5 >= 3
returns 1
 <= Less than or equal to 5 <= 3 return 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

 The #include directives “paste” the contents of the


files stdio.h, stdlib.h and string.h into your source
code, at the very place where the directives
appear.
 These files contain information about some
library functions used in the program:
 stdio stands for “standard I/O”, stdlib stands for
“standard library”, and string.h includes useful string
manipulation functions.
#define MAX_COLS 20
#define MAX_INPUT 1000

 The #define directives perform


“global replacements”:
◦ every instance of MAX_COLS is replaced with 20, and
every instance of MAX_INPUT is replaced with 1000.
int read_column_numbers( int columns[], int
max );
void rearrange( char *output, char const
*input,
int n_columns, int const columns[] );

 These look like function definitions – they have


the name and all the type information – but each
ends abruptly with a semicolon. Where’s the body
of the function – what does it actually do?
 (Note that each function does have a real
definition, later in the program.)
 main() is always the first function called in a program
execution.

int
main( void )
{ …

 void indicates that the function takes no arguments


 int indicates that the function returns an integer value
 Q: Integer value? Isn’t the program just printing out some
stuff and then exiting? What’s there to return?
 A: Through returning particular values, the program can
indicate whether it terminated “nicely” or badly; the
operating system can react accordingly.
printf( "Original input : %s\n", input );
 printf() is a library function declared in
<stdio.h>
 Syntax: printf( FormatString, Expr, Expr...)
◦ FormatString: String of text to print
◦ Exprs: Values to print
◦ FormatString has placeholders to show where to put
the values (note: #placeholders should match #Exprs)
◦ Placeholders: %s (print as string), %c (print as char),
%d (print as integer),
%f (print as floating-point)
◦ \n indicates a newline character
 In C, the three concepts are indeed closely
related:
◦ A pointer is simply a memory address. The type char
* “pointer to character” signifies that the data at the
pointer’s address is to be interpreted as a character.
◦ An array is simply a pointer – of a special kind:
 The array pointer is assumed to point to the first of a
sequence of data items stored sequentially in memory.
 How do you get to the other array elements? By
incrementing the pointer value.
◦ A string is simply an array of characters – unlike
Java, which has a predefined String class.
Hello World Program:-

#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
#include <stdio.h>
int main()
{
int firstNumber, secondNumber,
sumOfTwonumbers;
printf("Enter two integers: ");
scanf("%d %d", &firstNumber, &secondNumber);
sumOfTwoNumbers = firstNumber +
secondNumber;
printf("%d + %d = %d", firstNumber, secondNumber,
sumOfTwoNumbers);
return 0;
}
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
printf("You entered: %d", number);
return 0;
}
#include <stdio.h>
int main()
{
double firstNumber, secondNumber, temporaryVariable;
printf("Enter first number: ");
scanf("%lf", &firstNumber);
printf("Enter second number: ");
scanf("%lf",&secondNumber);
temporaryVariable = firstNumber;
firstNumber = secondNumber;
secondNumber = temporaryVariable;
printf("\nAfter swapping, firstNumber = %.2lf\n", firstNumber);
printf("After swapping, secondNumber = %.2lf", secondNumber);
return 0;
}
 Instructions which define general loops (for, while instruction etc...) or jumps
(goto, etc...). General loops will not be treated as instructions, but using
another programming mechanism, for the reason we want to control their
execution.
 Some less useful operators &&, ||, are not defined since they can easily be
replaced by the logical operators. Similarly, shift operators << or >>, which
corresponds to some multiplications with eventually other mask manipulation
are avoided. Furthermore, complex affectations, e.g. +=, *=, etc... or
incremental x++ operators which can be considered as compact expression
builded from other defined operators are not introduced.Again, all these
operators could have been defined, but they will not be very useful here. From
a programmer point of view, the main use of these operators are the fact they
might lead to more efficient compilations. This is nowadays not very true,
because usual compilers indeed optimize the code even if the programmer
has not written it in a very compact form. For instance, x=x+1 will obviously
be implemented, as x+=1 or even x++.
 The indirect operator * and reference operator & is not to be defined since we
do not manipulate pointers explicitly.
 The conditional operator expr ? val1 : val0 is not defined, since this is
redundant with the instruction.
Any Queries??????????
Thank You For Watching...

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy