Posts

C language: Chapter 5: Functions and pointers

Image
  Function - Function is a self-contained block of statements that performs a coherent task of some kind. @program Main () is the calling function and raj (), mahesh () are the called functions. Summary: - C program is a collection of one or more functions. Any C program contains at least one function. If there is only one function available in C program, it should be main (). If there are more than one functions available in C program, then one (one and only one) function should be main (), as programs begins with main (). There is no limit on the number of functions available in C program. Each function in a program is called, in the sequence specified by the function calls in the main (). When the called function has done its things, control returns to the main function. When main function runs out of the functions call, the program ends. A function gets called when a function name is followed by a semicolon. A function is defined when a function name is followed by pair of brac...

C Language: Chapter 4 The case control structure.

Image
  Switch is the case control statement that allows us to make a decision from the number of choices. It is also called switch case default. These three keywords go together to make up the control statement. Syntax of switch case default The integer expression following the switch keyword is any c expression that yields the integer value. [Characters also since they do have ASCII value interpretations] It could be an integer constant like 1, 2 or 3 or any expression that evaluates to an integer. The keyword case followed by an integer constant or character constant. Each constant in each case must be different from all other cases. The integer expression following the keyword switch is evaluated and yields an integer value. The integer value must be matched across the cases. When a match is found-The program executes following     1. The statement following that case.     2. All subsequent cases.     3. Default case as well. Keyword break stops executin...

C language : Chapter 3: For loop

Image
  For loop - for loop allows us to specify three things about the loop in a single statement. Setting the loop counter to initial value. Testing the loop to determine if the loop counter value has reached the number of repetitions desired. Increment the loop counter value each time, the program segment within the loop has executed. Syntax: For (initialize counter, test counter, increment counter) { Do this; And this; And this; } For loop structure Below for loops are perfectly ok. for(i=10;i;i--) printf("%d",i); please note:- i++ , i=i+1; i+=1 are same. @program- Write down a program for 1 to 10. method1 method2 Method3 Method4 Method5: Post increment operator Method 6: Pre increment operator Nesting of loops: Loops can be nested into one another and within itself. for loop can be nested within for loop while loop can be nested within for loop for loop can be nested within while loop. For loop within for loop Multiple initializations within for loop. The init...

C Language : Chapter 3 : While loop

Image
 Loops If something is worth doing, it's worth doing more than once. The versatility of computer lies in its ability to perform a set of instructions repeatedly. This involves repeating some portion of the program either a specific number of times or until a condition is being satisfied. This is done by loop control instructions. There are three methods by which we can repeat some portion of the program. while do while for Syntax of while loop initialize loop counter; while (test condition) { execute statement; increment counter; } @program- Flow chart Loop Counter / Index variable - Count variable sometimes called index variable or loop counter. in above program, variable count is loop counter or index variable. It is not necessary that the loop counter should always be an integer value. It can be real number as well. Instead of increment the loop counter we can decrement it as well. Other conditions which can be tested in while loops are: while (i<=10) while (i>=10 &...

C language : Chapter 2

Image
 Decision Control Instructions There are 3 major decision control instructions. if if-else switch the condition operators [ ternary operators] Syntax of If if(expression) execute the statement;                         //  ; statement terminator If the expression is true, execute the immediate next statement.  If the expression is false skip the statement. How do we evaluate if the expression is true or false. with the help of relational operators, we will evaluate that the expression is true or false. we will determine whether two statements are equal, unequal or one is greater than other. In C language, all arithmetic expressions are valid. They are considered as true or non-zero values. In C language, every test expression is evaluated as zero or non-zero value. Zero is equal to false and non-zero is equal to True. Scope of if By default, scope of if is the immediate next statement after it. If we want mor...

C language Chapter 1 programs

Image
    Program to calculate Simple Interest Program to perform arithmetic operations on ASCII values. Program to check math library to test exponential 

C Language chapter 1

Image
   Communicating with computers involve speaking a language that computer understands. Computer Language has 4 aspects. 1. How it stores data. 2. How it operates on data. 3. How it handles input and output. 4. How it controls the sequence of execution of instructions in a program. Background of C language 1. C was developed by AT&T bell laboratories of USA in 1972. It was designed and written by man named Dennis Ritchie. 2. In late 70s C language began to replace the most popular and familiar languages of that time, PL/I, ALGOL, PASCAL, APL, etc. 3. No on pushed C, it was not made official bell labs language. Thus, without any advertisement, C's reputation began to spread, and its pool of users grew.  4. C Language survived more than 3 decades. 5. To learn C++, JAVA, which has classes, objects, inheritance, polymorphism, Templates, exceptional handling and references, it is very important to learn C. 6. To organize the program C++, JAVA make use of principle called OO...