Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture by B.S.S.Tejesh, S.Neeraja Asst.Prof, ECE Dept

Similar presentations


Presentation on theme: "Lecture by B.S.S.Tejesh, S.Neeraja Asst.Prof, ECE Dept"— Presentation transcript:

1 Lecture by B.S.S.Tejesh, S.Neeraja Asst.Prof, ECE Dept
C-Language Lecture by B.S.S.Tejesh, S.Neeraja Asst.Prof, ECE Dept Mobile Num: Mail id:

2 Contents What is a computer Introduction to Programming Language
History of C Characteristics of C language Structure of C programs Compilation and execution of C Programs C character set, C keywords Identifiers, Data types, Constants, Variables, Expressions, Comments, printf, scanf, sample programs and exercise files. mailid:

3 What is a Computer? Computer is an electronic device which has the capability to Accept the data Store the data Process the data Generate the data Transmit the data Data: Raw facts that the computer can manipulate. Raw facts in the sense are letters, Numbers, Sounds, Images. Instruction: Command that a computer can understand. Program: A Set of Instructions. mailid:

4 Generations of Computers
First generation – Vacuum Tubes Second Generation – Transistors Third Generation – Integrated Circuits Fourth Generation – Microprocessor Fifth Generation – Advanced Processors mailid:

5 What is a Programming Language?
A programming language is a set of special kind of instructions which is used to communicate with a computer. The program will contain a list of steps that guides the computer to perform something that the user wants. Classified into two types High Level Programming Language Low level Programming Language mailid:

6 High Level Language These are similar to English like language.
Easy to write and understand the programs in high level language. No need to worry about the machine code, the programmer has to indeed think about the logic. Compilers are used to translate high to machine level language. Ex: C, Java, Python, PHP, C++, C#.Net, MySql, Objective C etc mailid:

7 Low level language It is also called as Assembly language.
Mainly utilized to work with microcontroller, microprocessors or any programmable devices. Assembler plays a crucial role in converting low level language into machine code. The Instructions in the low level languages are mnemonics i.e ADD, SUB, MOV. Ex: Assembly programming mailid:

8 History of C language C is a programming Language invented in the year by Dennis Ritchie at AT and T Bell Lab USA. C is a basic, fundamental, Feature rich, power full programming language using which we can develop computer programs. C language is primarily developed for developing a Operating system i.e UNIX. mailid:

9 Characteristics of C language
It is a middle level language. C makes it suitable for writing both application programs and system programs. It is an excellent, efficient and general-purpose language. C is small language, consisting of only 32 English words known as keywords. The power of C is augmented by the library functions provided with it. mailid:

10 C provides bit-wise operators for bit level manipulation.
C contains control constructs needed to write a structured program hence it is considered a structure programming language. It includes structures for selection (if.. .else, switch), repetition (while, for, do... while) and for loop exit (break). C provides bit-wise operators for bit level manipulation. All the above characteristics made the C language suitable for programming. mailid:

11 Features of C language C is a structured programming language.
It is a strictly typed language. It supports data structures, Memory allocation. It is a function oriented language. It facilitates file handling. It supports graphic and music. Interrupts can be built using C language mailid:

12 Structure of C language
mailid:

13 Preprocessor directives: Starts with a # pound sign.
Comments section: It is also called as documentation section and are usually enclosed between /* and */ Preprocessor directives: Starts with a # pound sign. Processed before the source code. #include and # define are two used preprocessor directives. Ex: #incude<stdio.h> #include<math.h> #define PI mailid:

14 To use some variables in many functions. Main Function:
Global Variables: To use some variables in many functions. Main Function: It is mandatory and execution of every C program starts with main(). Two main parts of main function are declaration of local variables and statements. User defined functions: Defined before or after main(). Can have local variables and statements. mailid:

15 Important shortcut keys while working with IDE
For Saving – F2 For compilation – Alt+ F9 For running – Ctrl+F9 For viewing Output – Alt+F5 mailid:

16 Steps in learning C language
mailid:

17 C Character set The different characters that are used for writing a c program is called a character set. 1. letters: Upper and lower case A-Z Upper case a-z lower case tejesh and Tejesh are different because C is a case sensitive language. 2.Digits: (0-9) 0,1,2,3,4,5,6,7,8,9 mailid:

18 3.Special Symbols: These are single characters and each single character has a special meaning and usage. mailid:

19 Escape Sequence characters
Characters are printed on the screen through the keyboard but some characters such as newline, tab, backspace cannot be printed like other normal characters. The escape sequences and are represented by two characters. The first character is "\" and second character is from the C character set. mailid:

20 mailid: tejeshbss@gmail.com. nerru8416@gmail.com

21 C tokens It represent unique entities using which we can write C Programs 6 types of C tokens Keywords Constants Identifiers Special symbols Strings Operators mailid:

22 Keywords in C Language 32 keywords are present in C language.
They are also called as reserved words or special words. They have a special meaning and functionality acc to programming standards. All the 32 keywords in C language are in lower case. C99 has 5 more keywords they are bool, complex, imaginary, inline, restrict. mailid:

23 List of keywords in C language
mailid:

24 Identifiers in C language
Identifiers are entities which are used to identify something uniquely in a program. Variable names, array names, function names, structure names, union names. Ex: int a,b; float x,y; Int a[5]; Struct employee{} Union employee{} mailid:

25 Rules for a identifier It should start with _ or A-Z or a-z or three of them combined together. Ex: Student_name, roll_Number, Phone_number1, _tejesh. No spaces are allowed. Can be of 1 to 32 characters in length. Keywords, special symbols cannot be used as a identifier. Invalid identifiers: 5bc, int, rec%, avg no mailid:

26 Constants in C language
It is a value that cannot be changed during execution of the program. They are also called as literals. mailid:

27 Numeric Constants Integer constants: Classified into three types
Decimal constants:0,1,2,3,4,5,6,7,8,9 Octal constants: 0,1,2,3,4,5,6,7 Hexa decimal constants: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Some valid integer constants are : 0,123, 3423, Some invalid integer constants are 2.5, 3#5, 33.55 Valid octal integer constants: 0,04, 0324. Valid Hexadecimal integer constants: 0X23, 0X424. mailid:

28 Real or Floating point constants
These are numeric constants with decimal points. Valid real constants are 0.4, 1.345, For expressing very large or very small real constants, exponential (scientific) form is used. Here the number is written in the mantissa and exponent form, Which are separated by ' e' or 'E'. Mantissa can be integer or real number, but exponent must be a integer number. can be written as 18e5, here 18 is mantissa and 5 is the exponent. mailid:

29 Character constants Character constant is a single character that is enclosed within single quotes. Valid character constants are: ‘A’, ‘$’, ‘1’, ‘ ’ Invalid character constants are: mailid:

30 every character constant has a unique integer value associated with it
every character constant has a unique integer value associated with it. This integer is the numeric value the character in the machine's character code or ASC11 code. mailid:

31 Valid String Constants:
String Constants: A String constant has zero, one or more than one character. A string constant is enclosed within double quotes (" "). At the end of string, \0 is 'automatically placed by the compiler. Valid String Constants: mailid:

32 Data types in C programming
It represents which type of data we are processing in a program to perform a task. mailid:

33 There are 4 fundamental datatypes which are int, char, float, double.
Char is used to store single character Int is used to store integer value Float is used to store single precision floating point number. Double is used to store double precision floating point number. There are two types of type qualifiers- 1. Size qualifiers: short, long 2. Sign qualifiers :signed, unsigned mailid:

34 mailid: tejeshbss@gmail.com. nerru8416@gmail.com

35 Sizeof() is responsible to find out the size of various data types.
#include<limits.h> is responsible for calculating the integral numbers range. #include<float.h> is responsible for calculating floating numbers range. Sizeof() is responsible to find out the size of various data types. mailid:

36 Output is 214 mailid:

37 Variables in C programming
In programming, a variable is a container (storage area) to hold data. To indicate the storage area, each variable should be given a unique name (identifier). Variable names are just the symbolic representation of a memory location. Ex: int playerScore = 95; Here, playerScore is a variable of integer type. The variable is assigned value: 95. The value of a variable can be changed. In C programming, you have to declare a variable before you can use it. mailid:

38 Declaration of variables
Declaration of a variable specifies it&name and datatype. The type and range of values that a variable can store depends upon its datatype. Syntax: datatype variablename; int x; float salary; char grade; int x,y,z; mailid:

39 Initialization of variables
When a variable is declared it contains undefined value commonly known as garbage value. mailid:

40 Types of Variables Local variable Global variable
mailid:

41 Local Variable The scope of local variables will be within the function only. These variables are declared within the function and can’t be accessed outside the function. In the below example, m and n variables are having scope within the main function only. These are not visible to test function. mailid:

42 Example of a local variable
mailid:

43 Output : mailid:

44 Global variable in C The scope of global variables will be throughout the program. These variables can be accessed from anywhere in the program. This variable is defined outside the main function. So that, this variable is visible to main function and all other sub functions. mailid:

45 Example of global variable
mailid:

46 Output: mailid:

47 Expressions in C programming
An expression is a combination of operators, constants, variables and function calls. The expression can be arithmetic, logical or relational. examples mailid:

48 Comments in C programming
Comments are used for increasing readability of the program. They explain the purpose of the program and are helpful in understanding the program. Comments are written inside /* and */. There can be single line or multiple line comments. We can write comments anywhere in a program except inside a string constant or a character constant. mailid:

49 Single and multiple line comment
mailid:

50 Predefined Functions Three main functions of any program is data as input, process the data, gives the output. The printf() and scanf() functions are inbuilt library functions in C programming language which are available in C library by default.  These functions are declared and related macros are defined in “stdio.h” which is a header file in C language. We have to include “stdio.h” file as shown in below C program to make use of these printf() and scanf() library functions in C language. mailid:

51 printf() In C programming language, printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen. Syntax: printf(“control string”, variable 1, variable 2…….); Ex: printf(“Welcome to c language”); printf(“enter your age”); int Basic=111; printf(“%d”, basic); mailid:

52 To generate a newline,we use “\n” in C printf() statement. Note point:
We use printf() function with %d format specifier to display the value of an integer variable. Similarly %c is used to display character, %f for float variable, %s for string variable, %lf for double and %x for hexadecimal variable. To generate a newline,we use “\n” in C printf() statement. Note point: C language is case sensitive. For example, printf() and scanf() are different from Printf() and Scanf(). All characters in printf() and scanf() functions must be in lower case. mailid:

53 Example Program mailid:

54 Output mailid:

55 Note Points %d got replaced by value of an integer variable (no),
%c got replaced by value of a character variable  (ch), %f got replaced by value of a float variable  (flt), %lf got replaced by value of a double variable  (dbl), %s got replaced by value of a string variable  (str) \n got replaced by a newline. mailid:

56 scanf() In C programming language, scanf() function is used to read character, string, numeric data from keyboard. Syntax: scanf(“control string”, address1, address 2………..); Examples: scanf(“%d”,&marks); scanf(“%f”,&hieght) ; scanf(“%d%f%c”,&a,&b,&c); mailid:

57 Consider below example program where user enters a character
Consider below example program where user enters a character. This value is assigned to the variable “ch” and then displayed. Then, user enters a string and this value is assigned to the variable “str” and then displayed. mailid:

58 Example program mailid:

59 output mailid:

60 It is just like in a pointer which is used to point to the variable
The format specifier %d is used in scanf() statement. So that, the value entered is received as an integer and %s for string. Ampersand is used before variable name “ch” in scanf() statement as &ch. It is just like in a pointer which is used to point to the variable mailid:

61 Formatted Input and Output
Formatted input and output means that data is entered and displayed in a particular format. Format for integer input: %wd, here d is the conversion character and w is an integer number. Example: scanf("%2d%3d", &a, &b ); a=43; b=655; mailid:

62 Format for integer output:
%wd, here d is the conversion character and w is an integer number. Example: printf("a=%3d, b=%4d", a, b ); mailid:

63 Example mailid:

64 Format For Floating Point Numeric Input
%wf Example:scanf("%3f %4f ", &x, &y); mailid:

65 Format For Floating Point Numeric Output
%w.nf Syntax: printf("x = %4.1f, y = %7.2f ", x, y); mailid:

66 Format for string input
%ws Example: char str [8] ; scanf ("%3s", str ); If the input is TEJESHBSS only first three characters of this input will be stored in the string, so the characters in the string will be ‘T', ‘E', ‘J', '\0' The null character('\O') is automatically stored at the end. mailid:

67 Format for string output
%w.ns mailid:

68 Character I/O getchar() putchar()
Performs operation only on single character mailid:

69 Sample programs session 1
1.Program to Display "Hello, World!" 2.Program to Print an Integer 3.Program working with Local variables 4.Program working with Global variables 5.Program to find the size of a variable 6. Program to work with printf 7. Program to work with scanf Practice problems mailid:


Download ppt "Lecture by B.S.S.Tejesh, S.Neeraja Asst.Prof, ECE Dept"

Similar presentations


Ads by Google