Posts

Showing posts from September, 2018

Way to Defined Functions in C Language

Image
WAY TO DEFINED FUNCTIONS EXAMPLE OF -- "TAKES NOTHING RETURNS NOTHING" NOTE--  The add() function takes input from the user i.e a&b and displays it on the screen. The empty parentheses in add() statement inside the main () function indicates that no argument is passed to the function. The return data type of the function is void. which indicates no value is returned from the function.(void is empty data type 2-TAKES SOMETHING AND RETURNS NOTHING example of function in c  NOTE - As we know that variables declaration in a function can not be accessed in any other function, but we want that if the data in the variable created in the main function is accessed in the add function, then at the time when compiler call the add function we have to pass the variable in its parenthesis  i.e x,y as shown in above example ,  when the add function is created, then the variable has to be declarated in parentheses i.e int a,int b

What is Function in C Language part-2

Image
WHAT IS FUNCTION ? piece of code to accomplish certain operation. It has a name for identification There are two types   predefined functions   user defined function EXAMPLE-- example of function in c Types of  functions in C  Depending on whether a function is defined by the user or already included in C compilers, there are two types of functions in C programming. There are two types of functions in C: Standard library functions  User defined functions Standard library functions The standard library functions are built-in functions in C programming to handle tasks such as mathematical computations. I/O processing, string handling etc. These functions are defined in the header file. When you include the header file, these function are available for use. For example: The printf() is standard library function to send formatted output to the screen (display output on the screen). This function is defined in "stdio.h"

Functions Overview in C Language part-1

Functions Overview Function is a basic building block of a C program. Any C program can be assumed as a collection of several functions. Function is a block of code which has some name for identification. Key Point of Function Function is a block of code, which has some name for identification Any C program can have any number of functions. At least one function should be there in the program Function names must be unique. No two functions can share same names No keyword is a functions, so do not misinterpreted by the syntax of if, while, switch, return(), sizeof(), etc, they are not functions Function cannot be defined inside body of another function Function call, function definition and function declaration are three different terminologies with different meanings, so never used them interchangeably You can call a function from a function any number of times, but can define only once. Function is a way to achieve modularization. Splitting up of a bi

Switch Case in C Language

Image
switch case in c We studied earlier in decision control that how and when to use if, if-else. They are good enough to select one from the two available options. When choices are two, we can use if-else. Even if we have multiple choices we can use multiple if-else, sometimes we use if-else ladder or nested if-else becomes more complex. Whenever we have many choices(cases) and we have to choose one of them(generally), it is better to use switch case control. In this section we are going to learn three keywords, case and default. Apart from these keywords we will also see usage of break keyword in switch body. Syntax  switch case in c Switch statement is used to solve multiple option type problems for menu like program, where one value is associated with each option. The expression in switch case evaluates to return an integral value, which is then compared to the values in different cases, where it matches that block of code is executed, if there is no match, then default

Keyword Break and Continue in C Language

Image
Keyword Break and Continue in C Language Break keyword Break keyword is used only in: In the body of loop In the body of switch The keyword break is used in the body of loop to terminate execution of loop before completion of normal life of the loop. Sometimes it is desired to terminate loop before its last iteration. For example we have to make a program to take input a number from user, which should be an even number. We give at the most three chances to the user to input correct value. It is like a game where user has three chances. If user entered an even number the game is in his pocket (win the game) otherwise he loses the game. Suppose user inputs an even number in the first chance, then no more chances are needed as he already wins the game. So we have to use break keyword to terminate the iterations. int main() { int x, i=1; while(i<3) { printf(" enter an even num"); scanf("%d", &x); if (x%2= = 0) { print

Iterative Control Instruction(Loops) in C Language

Image
Iterative Control Instruction (Loops) Loops Iterative control instruction is also known as repetitive control instruction or loop. Iterative control instruction is also known as repetitive control instruction or loop. Sometimes it is desirable to executed same statement again and again. This can be done with the help of loops. There are three ways to implement loops in C language: while loop int main () { ........ ...... while (condition) { .... .... } ..... } Syntax of while is similar to if. In the case of if, when the condition is TRUE control moves inside if block and execute statement of if-block. After executing if-block control moves to the statement written immediately after if-block (outside if-block). In the case of while, when the condition is TRUE control moves inside while-block and execute statements of while-block. After executing while-block control does not move to the statement written immediately after while

Control Instructions and if,else if and nested if in C Language

Image
 Control Instructions in C Program is a set of instructions. We know that each instruction of the program is executed by processor. Processor executes instructions one by one. Whatever we write in our program is executed in the same order as they appear in the program. We can say processor executes instructions in a sequential manner. At a particular instant processor is executing some line of code, we say control pf processor is on that line. Processor's control moves from one line to another. This movement of control is known as flow of the program. Sometimes, it is required that the program's flow shouldn't be sequential. For example, we want to execute first line of our program, then second and third line but after executing third line, we may want to skip fourth line and jump to the fifth line. In such situations, we use control instructions. Control instruction gives power to decide the flow of the program. There are four types of control instructions:

Ternary and Assignment Operators in C Language

Ternary and Assignment Operators in C Language Ternary Operator (?:) A conditional operator is a ternary operator, that is, it work on 3 operands. Syntax conditional Expression ? expression 1 : expression 2 Working of Conditional operator :- The first expression conditional Expression is evaluated first. This expression evaluates to 1 if it's true and evaluates to 0 if it's false. If conditional Expression is true, expression 1 is evaluated. If conditional Expression is false, expression 2 is evaluated. Example : #include <stdio.h> int main () { char february; int days; printf(" if this year is leap year, enter 1. if not enter any integer: "); scanf(" %c", & february); days = (february == '1') ? 29 : 28; printf(" number of days in february = %d", days); return 0; } Output if this year is leap year, enter 1. if not enter any integer: 1 Number of days in february = 29 Assign

Logical Operators in C Language

Image
Logical Operators An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false. Here above 3 Logical Operator are arrange in according to it's priority order i.e           NOT>AND>OR . NOT Logical Operator EXAMPLE  OF ! Example of ! operator OUTPUT :-  0 Note :-  In the quotation given above, Output is zero because the ! is a unary operator so first of all, the !x has run and in place of !x the value come 0  then next expression i.e 0>4 is solve . AND Logical Operator syntax of && operator EXAMPLE  OF && Example of && operator OUTPUT :-  0 NOTE:--  Here in above example y=x>4&&x<10 , first of all x>4 is solve because it's                                    priority order higher then amongs all so in place of x>4 , 1 value is come                                        then &