1 / 15

Basics of C language

Basics of C language. Contents. Introduction Strengths & Weakness of C Language Character Set Keywords Identifiers Variables Constants Data Types . Introduction. C is a general-purpose high level language that was developed by Dennis Ritchie . Features of C language are :

jariah
Download Presentation

Basics of C language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basics of C language

  2. Contents • Introduction • Strengths & Weakness of C Language • Character Set • Keywords • Identifiers • Variables • Constants • Data Types

  3. Introduction C is a general-purpose high level language that was developed by Dennis Ritchie . Features of C language are : • Easy to learn. • Structured language. • It produces efficient programs. • It can handle low-level activities. • It can be compiled on a variety of computers. Back

  4. Strengths & Weakness of C Language Strengths of C Language: • Efficiency • Portability • Power • Flexibility • Standard Library Weakness of C Language: • Error Prone • Difficult to understand • Difficult to modify Back

  5. Character Set C does not use, nor requires the use of, every character found on a modern computer keyboard. The only characters required by the C Programming Language are as follows: • Uppercase: A B C  ....................................  X Y Z  • Lowercase: a b c  ......................................  x y z • Digits: 0 1 2 3 4 5 6  8 9 - • Special Characters: <>._();$:%[]#?'&{}"^!*/|-\~+  • White space Characters: blank space, new line, horizontal tab, carriage return and form feed Back

  6. Keywords Keywords are the reserved words used in programming. Each keywords has fixed meaning and that cannot be changed by use. auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while Back

  7. Identifiers In C programming, identifiers are names given to C entities, such as variables, functions, structures etc. Identifier are created to give unique name to C entities to identify it during the execution of program. For example: int money; Here, money is a identifier which denotes a variable of type integer. Rules for writing identifier • An identifier can be composed of letters (both uppercase and lowercase letters), digits and underscore '_' only. • The first letter of identifier should be either a letter or an underscore. But, it is discouraged to start an identifier name with an underscore though it is legal. It is because, identifier that starts with underscore can conflict with system names. In such cases, compiler will complain about it. Some system names that start with underscore are _fileno, _iob, _wfopen etc. • There is no rule for the length of an identifier. However, the first 31 characters of an identifier are discriminated by the compiler. So, the first 31 letters of two identifiers in a program should be different Back

  8. Variables Variables are memory location in computer's memory to store data. To indicate the memory location, each variable should be given a unique name called identifier. Variable names are just the symbolic representation of a memory location. Examples : sum ,add. Rules for writing variable name in C • Variable name can be composed of letters (both uppercase and lowercase letters), digits and underscore '_' only. • The first letter of a variable should be either a letter or an underscore. But, it is discouraged to start variable name with an underscore though it is legal. It is because, variable name that starts with underscore can conflict with system names and compiler may complain. • There is no rule for the length of length of a variable. However, the first 31 characters of  a variable are discriminated by the compiler. So, the first 31 letters of two variables in a program should be different. Back

  9. Constants Constants are the terms that can't be changed during the execution of a program. For example: 1, 2.5, "Programming is easy." etc. Constants can be classified as: • Integer constants: Integer constants are the numeric constants without any fractional part or exponential part. There are three types of integer constants in C language: decimal constant(base 10), octal constant(base 8) and hexadecimal constant(base 16) . Decimal constants: 0, -9, 22 etc Octal constants: 021, 077, 033 etc Hexadecimal constants: 0x7f, 0x2a, 0x521 etc . • Floating-point constants : Floating point constants are the numeric constants that has either fractional form or exponent form. For example: -2.0 , 0.0000234 , -0.22E-5 • Character constants: Character constants are the constant which use single quotation around characters. For example: 'a', 'l', 'm', 'F' etc.

  10. String constants:String constants are the constants which are enclosed in a pair of double-quote marks. • "good“ //string constant • “ " //null string constant • “ " //string constant of six white space • "x“ //string constant having single character. • "Earth is round\n" //prints string with newline • Escape Sequences: Sometimes, it is necessary to use newline(enter), quotation mark etc. in the program which either cannot be typed or has special meaning in C programming. Escape SequencesCharacter \b Backspace \f Form feed \n Newline \r Return \‘ Single quotation mark \" Double quotation mark Back

  11. Data Types In C, variable(data) should be declared before it can be used in program. Data types are the keywords, which are used for assigning a type to a variable. • Data types in C: Fundamental Data TypesDerived Data Types Integer types Arrays Floating Type Pointers Character types Structures Enumeration • Syntax for declaration of a variable: data_type variable name; • Integer data types: Keyword int is used for declaring the variable with integer type. For example : int var1;

  12. Basic Integer Types

  13. Floating Data Types: Variables of floating types can hold real values(numbers) such as: 2.34, -9.382 etc. Keywords either float or double is used for declaring floating type variable. • float single-precision floating-point • double double-precision floating-point • long double extended-precision floating-point

  14. Character types : Keyword char is used for declaring the variable of character type. For example: char var4='h'; Here, var4 is a variable of type character which is storing a character 'h'. The size of char is 1 byte. The character data type consists of ASCII characters. Each character is given a specific value. For example: For, 'a', value =97 For, 'b', value=98 For, 'A', value=65 For, '&', value=33 For, '2', value=49 Back

  15. Thank You

More Related