We can also declare and define a variable in single shot like this. int a=10;

Format specifiers %d is the format specifier. This informs to the compiler that the incoming value is an integer value. Other data types can be specified as follows: %c – character %f – float %lf – double %s – character array (string) Printf and scanf are defined under the header file stdio.h

4.
Header files <ul><li>The files that are specified in the include section is called as header file </li></ul><ul><li>These are precompiled files that has some functions defined in them </li></ul><ul><li>We can call those functions in our program by supplying parameters </li></ul><ul><li>Header file is given an extension .h </li></ul><ul><li>C Source file is given an extension .c </li></ul>Thursday, September 1, 2011

5.
Main function <ul><li>This is the entry point of a program </li></ul><ul><li>When a file is executed, the start point is the main function </li></ul><ul><li>From main function the flow goes as per the programmers choice. </li></ul><ul><li>There may or may not be other functions written by user in a program </li></ul><ul><li>Main function is compulsory for any c program </li></ul>Thursday, September 1, 2011

6.
Writing the first program <ul><li>#include<stdio.h> </li></ul><ul><li>int main() </li></ul><ul><li>{ </li></ul><ul><li>printf(“Hello”); </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul><ul><li>This program prints Hello on the screen when we execute it </li></ul>Thursday, September 1, 2011

7.
Running a C Program <ul><li>Type a program </li></ul><ul><li>Save it </li></ul><ul><li>Compile the program – This will generate an exe file (executable) </li></ul><ul><li>Run the program (Actually the exe created out of compilation will run and not the .c file) </li></ul><ul><li>In different compiler we have different option for compiling and running. We give only the concepts. </li></ul>Thursday, September 1, 2011

11.
Variable names- Rules <ul><li>Should not be a reserved word like int etc.. </li></ul><ul><li>Should start with a letter or an underscore(_) </li></ul><ul><li>Can contain letters, numbers or underscore. </li></ul><ul><li>No other special characters are allowed including space </li></ul><ul><li>Variable names are case sensitive </li></ul><ul><ul><li>A and a are different. </li></ul></ul>Thursday, September 1, 2011

12.
Input and Output <ul><li>Input </li></ul><ul><ul><li>scanf(“%d”, & a); </li></ul></ul><ul><ul><li>Gets an integer value from the user and stores it under the name “a” </li></ul></ul><ul><li>Output </li></ul><ul><ul><li>printf(“%d”,a); </li></ul></ul><ul><ul><li>Prints the value present in variable a on the screen </li></ul></ul>Thursday, September 1, 2011

21.
Procedures <ul><li>Procedure is a function whose return type is void </li></ul><ul><li>Functions will have return types int, char, double, float or even structs and arrays </li></ul><ul><li>Return type is the data type of the value that is returned to the calling point after the called function execution completes </li></ul>Thursday, September 1, 2011

24.
Actual and Formal parameters <ul><li>Actual parameters are those that are used during a function call </li></ul><ul><li>Formal parameters are those that are used in function definition and function declaration </li></ul>Thursday, September 1, 2011

25.
Arrays <ul><li>Arrays fall under aggregate data type </li></ul><ul><li>Aggregate – More than 1 </li></ul><ul><li>Arrays are collection of data that belong to same data type </li></ul><ul><li>Arrays are collection of homogeneous data </li></ul><ul><li>Array elements can be accessed by its position in the array called as index </li></ul>Thursday, September 1, 2011

26.
Arrays <ul><li>Array index starts with zero </li></ul><ul><li>The last index in an array is num – 1 where num is the no of elements in a array </li></ul><ul><li>int a[5] is an array that stores 5 integers </li></ul><ul><li>a[0] is the first element where as a[4] is the fifth element </li></ul><ul><li>We can also have arrays with more than one dimension </li></ul><ul><li>float a[5][5] is a two dimensional array. It can store 5x5 = 25 floating point numbers </li></ul><ul><li>The bounds are a[0][0] to a[4][4] </li></ul>Thursday, September 1, 2011

27.
Structures <ul><li>Structures are user defined data types </li></ul><ul><li>It is a collection of heterogeneous data </li></ul><ul><li>It can have integer, float, double or character data in it </li></ul><ul><li>We can also have array of structures </li></ul><ul><li>struct <<structname>> </li></ul><ul><li>{ </li></ul><ul><li>members; </li></ul><ul><li>}element; </li></ul><ul><li>We can access element.members; </li></ul>Thursday, September 1, 2011

29.
Type def <ul><li>The typedef operator is used for creating alias of a data type </li></ul><ul><li>For example I have this statement </li></ul><ul><ul><li>typedef int integer; </li></ul></ul><ul><ul><li>Now I can use integer in place of int </li></ul></ul><ul><ul><li>i.e instead of declaring int a;, I can use </li></ul></ul><ul><ul><li>integer a; </li></ul></ul><ul><ul><li>This is applied for structures too. </li></ul></ul>Thursday, September 1, 2011

30.
Pointers <ul><li>Pointer is a special variable that stores address of another variable </li></ul><ul><li>Addresses are integers. Hence pointer stores integer data </li></ul><ul><li>Size of pointer = size of int </li></ul><ul><li>Pointer that stores address of integer variable is called as integer pointer and is declared as int *ip; </li></ul>Thursday, September 1, 2011

33.
Call by Value <ul><li>Calling a function with parameters passed as values </li></ul><ul><li>int a=10; void fun(int a) </li></ul><ul><li>fun(a); { </li></ul><ul><li>defn; </li></ul><ul><li>} </li></ul><ul><li>Here fun(a) is a call by value. </li></ul><ul><li>Any modification done with in the function is local to it and will not be effected outside the function </li></ul>Thursday, September 1, 2011

38.
Explanation a and x are referring to same location. So value will be over written. Thursday, September 1, 2011

39.
Conclusion <ul><li>Call by value => copying value of variable in another variable. So any change made in the copy will not affect the original location. </li></ul><ul><li>Call by reference => Creating link for the parameter to the original location. Since the address is same, changes to the parameter will refer to original location and the value will be over written. </li></ul>Thursday, September 1, 2011