Presentation is loading. Please wait.

Presentation is loading. Please wait.

By: Syed Shahrukh Haider

Similar presentations


Presentation on theme: "By: Syed Shahrukh Haider"— Presentation transcript:

1 By: Syed Shahrukh Haider
C Building Block By: Syed Shahrukh Haider

2 Introduction Three importance aspects of any language are the way it stores data, how it accomplished input & output, and the operator it uses to transform and combine data.

3 Variable 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

4 Type of Variable C Sr.No. Type & Description 1 char
Typically a single octet(one byte). This is an integer type. 2 int The most natural size of integer for the machine. 3 float A single-precision floating point value. 4 double A double-precision floating point value. 5 void Represents the absence of type.

5 A variable definition tells the compiler where and how much storage to create for the variable. A variable definition specifies a data type and contains a list of one or more variables of that type as follows − type variable_list; Here, type must be a valid C data type including char, w_char, int, float, double, bool, or any user-defined object; and variable_list may consist of one or more identifier names separated by commas. Some valid declarations are shown here − int i, j, k; char c, ch; float f, salary; double d;

6 type variable_name = value;
The line int i, j, k; declares and defines the variables i, j, and k; which instruct the compiler to create variables named i, j and k of type int. Variables can be initialized (assigned an initial value) in their declaration. The initializer consists of an equal sign followed by a constant expression as follows − type variable_name = value;

7

8 Example of Variable Void main(void){ Int event; char heat; float time; event = 5; heat = ‘C’; time = 27.25; printf(“The winning time in heat %c”, heat); printf(“ of event %d was &f.”, event, time); }

9 Initializing Variable
Void main(void){ Int event = 5; char heat =‘C’; float time = 27.25; printf(“The winning time in heat %c”, heat); printf(“ of event %d was &f.”, event, time); }

10 Output %c – single character %s – string %d – signed decimal integer
Command: Printf(); %c – single character %s – string %d – signed decimal integer %f – floating point [decimal notation] %e – floating point [exponential notation] %g – floating (%f or %e whichever is shorter) %u – unsigned decimal %x – unsigned hexdecimal %o – unsigned octal

11 Printf() Format String
Signal Format Field width Number of digits to right of decimal place Indicated Decimal-format “floating point” % 6 0 . 1 f

12 Escape Sequences Escape sequences are used in the programming languages C and also in many more languages An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly.

13

14 Input Void main(void){ Int event; char heat; float time;
Command: scanf(); Void main(void){ Int event; char heat; float time; printf (“enter value of: event,heat & time”) scanf(“%d, %c, %f”, &event &heat &time); printf(“The winning time in heat %c”, heat); printf(“ of event %d was &f.”, event, time); } (&) ampersand = act as pointer to variable to used for storing the input

15 Some other input command
getche() getchar() = require [return/enter] key as input get = get value ch = char e= echo the char

16 Arithemtic Operator + : Addition example: x = x + y
- : Subtraction example: x = x - y * : Multiplication example: x = x * y / : Division example: x = x / y % : remainder example: x = x % y

17 Arithmetic Assignment Operator
+= : addition assignment operator example: x += y -= : subtraction assignment operator example: x -= y *= : multiplication assignment operator example: x *= y /= : division assignment operator example: x /= y %=: reminder assignment operator example: x %= y

18 Increment Operator ++ : increment -- : Decrement

19 Relational Operator < : less than > : greater than == : equal to
<= : less than & equal to >= : greater than & equal to != : no equal to

20 Comment /* Single line or paragraph that one can state during writing code, this will assist programmer comment out coding or some important feature that can help him or some else to understand in future. But these lines will not interfere during compile/build */


Download ppt "By: Syed Shahrukh Haider"

Similar presentations


Ads by Google