29
FUNDAMENTALS OF “C” GOVERNMENT ENGINEERING COLLEGE BHARUCH SUB:- COMPUTER PROGRAMMING AND UTILIZATION RATHVA RAVIKUMAR 160140119093 RATHOD PRASHANANT 160140119094 RATHVA RAHULKUMAR 160140119095 RAVAL KRUNAL 160140119096

FUNDAMENTAL OF C

Embed Size (px)

Citation preview

Page 1: FUNDAMENTAL OF C

FUNDAMENTALS OF “C”GOVERNMENT ENGINEERING COLLEGE

BHARUCH

SUB:- COMPUTER PROGRAMMING AND UTILIZATION

• RATHVA RAVIKUMAR 160140119093• RATHOD PRASHANANT 160140119094• RATHVA RAHULKUMAR 160140119095• RAVAL KRUNAL 160140119096

Page 2: FUNDAMENTAL OF C

Comments:-• Comments are used in a programme to improve the

understanding.• Comments are not executed, rather they are ignored by the

compiler.• Comments help the programme to understand the various

operations of a program and serve as an aid to debugging and testing.

• Single line comments start with // symbol and multiple line comments are written within /* and */.

Page 3: FUNDAMENTAL OF C

Header files:-• A header file is a file with extension .h which contains C

function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler

Page 4: FUNDAMENTAL OF C

Character set:-• The character set is the fundamental raw material of any

language and they are used to represent information. Like natural languages, computer language will also have well defined character set, which is useful to build the programs. Alphabets. Uppercase letters A-Z.

• Characters are used to write tokens .these characters are defined by the Unicode character set.

• The C Character set includes letter , digits, special characters and white spaces as building blocks to form blocks to form basic programming elements.

Page 5: FUNDAMENTAL OF C

Character set:-

Page 6: FUNDAMENTAL OF C

Tokens:-• A programming token is the basic component of source code .

Character s are categorized as one of five classes of tokens that describe their functions (constants, identifiers, operators, reserved words, and separators) in accordance with. the rules of the programming language

Page 7: FUNDAMENTAL OF C

Keywords:-

•Auto:• Defines a local variable as having a local lifetime.• Keyword auto uses the following syntax:• [auto] data-definition • As the local lifetime is the default for local variables, auto keyword is extremely

rarely used. 

•Break:• Passes control out of the compound statement.• The break statement causes control to pass to the statement following the innermost

enclosing while, do, for, or switch statement. • The syntax is simply:• break;

Page 8: FUNDAMENTAL OF C

Const:-• Makes variable value or pointer parameter unmodifiable.• When const is used with a variable, it uses the following syntax:• const variable-name [ = value]; • In this case, the const modifier allows you to assign an initial

value to a variable that cannot later be changed by the program. For example,

Page 9: FUNDAMENTAL OF C

Continue:-• Passes control to the begining of the loop.• continue causes control to pass to the end of the innermost enclosing while, do,

or for statement, at which point the loop continuation condition is re-evaluated.• The syntax is simply:• Continue

Do/Do-while loop:-• Keyword do is usually used together with while to make another form of

repeating statement.• Such form of the loop uses the following syntax:• do statement while (expression)e;

Page 10: FUNDAMENTAL OF C

Enum :-• Defines a set of constants of type int.• The syntax for defining constants using enum is• enum [tag] {name [=value], ...};

Float, double:-• The keyword float usually represents a single precision floating point data

type, and double represents a double precision floating point data type. In TIGCC, both float and double (and even long double) are the same. The TI-89 and TI-92 Plus use a non-IEEE floating point format called SMAP II BCD for floating point values. 

These values have a range from 1e-999 to 9.999999999999999e999 in magnitude, with a precision of exactly 16 significant digits. Principally, the exponent range may be as high as 16383, but a lot of math routines do not accept exponents greater than 999.

Page 11: FUNDAMENTAL OF C

For loop:-• For-loop is yet another kind of loop. It uses for keyword, with

the following syntax:• for ([expr1]; [expr2]; [expr3]) statement

Goto :-• goto may be used for transfering control from one place to

another. The syntax is:• Goto identifier; Control is unconditionally transferred to the

location of a local label specified by identifier. For example,• Again: ... Goto Again;

Page 12: FUNDAMENTAL OF C

While:-• Repeats execution while the condition is true.• Keyword while is the most general loop statemens. It uses the following

syntax:• while (expression) statement

Basic data types (integer and character:-• Variables of type int are one machine-type word in length. They can be signed

 (default) or unsigned, which means that in this configuration of the compiler they have by default a range of -32768 to 32767 and 0 to 65535 respectively, but this default may be changed if the compiler option '-mnoshort' is given. In this case, the range of type int is -2147483648 to 2147483647 for signed case, or 0 to 4294967295 for unsigned case. See also short and long type modifiers

Page 13: FUNDAMENTAL OF C

Identifiers:-• Alphabets, digits, underscores are permitted.• They must not begin with a digit.• First character must be letter.• They may also begin with an underscore.• Uppercase and lower case letters are distinct.• They can be of any length however the frist 8 characters are

treated as significant by the C compiler.• Declared keywords cannot be used as variable.

Page 14: FUNDAMENTAL OF C
Page 15: FUNDAMENTAL OF C

Constants:-

Page 16: FUNDAMENTAL OF C

Constants:-

Constant Type of Value Stored

Integer Constant Constant which stores integer valueFloating Constant Constant which stores float valueCharacter Constant Constant which stores character value

String Constant Constant which stores string value

Page 17: FUNDAMENTAL OF C

Integer constants:-• Any whole number value is an integer.• An integer constant refers to a sequence of digits without a

decimal point.• An integer preceded by a unary minus may be considered to

represent a negative constant•     Example:            0          -33      32767

There are three types of integer constants namely,                a)     Decimal integer constant                                      b)     Octal integer constant                c)     Hexadecimal integer constant                  

Page 18: FUNDAMENTAL OF C

Decimal Integer constant :-  

• It consists of any combinations of digits taken from the set 0 through 9, preceded by an optional – or + sign.

• The first digit must be other than 0.• Embedded spaces, commas, and non-digit characters are not

permitted between digits. •     Valid:             0          32767     -9999          -23

    Invalid:                         12,245            -   Illegal character (,)

10  20  30       -   Illegal character (blank space)

Page 19: FUNDAMENTAL OF C

•Octal Integer Constant :-

• It consists of any combinations of digits taken from the set 0 through 7.

• If a constant contains two or more digits, the first digit must be 0.

• In programming, octal numbers are used.•     Valid:                   037                 0          0435

    Invalid:                            0786               -           Illegal digit 8                            123                 -           Does not begin with

zero                              01.2                -           Illegal character (.)

Page 20: FUNDAMENTAL OF C

Hexadecimal integer constant :-• It consists of any combinations of digits taken from the set 0 through 7 and

also a through f (either uppercase or lowercase).• The letters a through f (or A through F) represent the decimal

quantities 10 through 15 respectively.• This constant must begin with either 0x or 0X.• In programming, hexadecimal numbers are used.•     Valid Hexadecimal Integer Constant:            0x            0X1             0x7F  

             Invalid Hexadecimal Integer Constant:                   0xefg  -           Illegal character g

123     -           Does not begin with 0x

Page 21: FUNDAMENTAL OF C

Unsigned integer constant:-        An unsigned integer constant specifies only positive integer value. It is used only to count things. This constant can be identified by appending the letter u or U to the end of the constant.  

Valid:             0u          1U         65535u       0x233AUInvalid:          -123      -         Only positive value

Long integer constant:-     A long integer constant will automatically be generated simply by specifying a constant that exceeds the normal maximum value. It is used only to count things. This constant can be identified by appending the letter l or L to the end of the constant.           

Valid:             0l23456L       0x123456L    -123456lInvalid:          0x1.2L            -           Illegal character (.)

Short integer constant:-   A short integer constant specifies small integer value. This constant can be identified by appending the letter s or S to the end of the constant.

Valid:             123s                -456           32767SInvalid:                                  12,245                   -    Illegal character (,)                        10  20  30  -   Illegal character (blank space

Page 22: FUNDAMENTAL OF C

Character constants:-

Page 23: FUNDAMENTAL OF C

String constant:-• It contains sequence of characters enclosed in double qutation

marks.• String constants are enclosed in double quotes "". A string

contains characters that are similar to character literals: plain characters, escape sequences, and universal characters.

• You can break a long line into multiple lines using string literals and separating them using white spaces.

• Here are some examples of string literals. All the three forms are identical strings.

• "hello, dear" "hello, \ dear" "hello, " "d" "ear"

Page 24: FUNDAMENTAL OF C

Backslash character constants(Escape sequences):-

• Enclosing character constants in single quotes works for most printing characters

• .A few , however, such as carriage return, can't be. For this reason, C includes special backslash character constants, so that you may easily enter these special characters as constants.

• You should use the backslash codes instead of their ASCII equivalents to help insure portability.

• List of backslash character constants are as follows:-

Page 25: FUNDAMENTAL OF C

Code Meaning:-• \b Backspace• \f Form feed• \n New line• \r Carriage return• \t Horizontal tab• \" Double quote• \' Single quote• \\ Backslash• \v Vertical tab• \a Alert(very small sound)• \? Question mark

• \N Octal constant (N is an octal constant)

• \xN Hexadecimal constant (N is an hexadecimal constant)

•  

Page 26: FUNDAMENTAL OF C

Special symbols:-• Parethesis ( ) : Used for surrounding cast types.• Braces{ } : Used to initialize the arrays, used to define a block

of code.• Brackets[ ] : Used to declare array types.

• Semicolon; : Used to separate statements.

• Comma, :Used to separate identifiers in a variable declaration.

• Ampersand & : Used to assign the address of the location of variable. used in the scanf function.

Page 27: FUNDAMENTAL OF C

Data types:-

Page 28: FUNDAMENTAL OF C

Data types:

Page 29: FUNDAMENTAL OF C

THANK YOU