Posts

Showing posts with the label C Programming Theory

Control Statements in C Programming | C Programming

Image
Control Statement Control statements enable us to specify the flow of program control i.e., the order in which the instructions in a program must be executed. They make it possible to make decisions, perform tasks repeatedly, or jump from one section of code to another. The different forms of if statements with their syntax and semantic diagram are: - If statements: -  The if statement evaluates the test expression inside the parenthesis. If the test expression is evaluated to true (non-zero), statements inside the body it is executed. If the test expression is evaluated to false (0), statements inside the body of if are skipped from execution. The Syntax and Semantics diagram are: if (test expression) {     (statements) } If else statement:  The if-else statement executes some code if the test expression is true (nonzero) and some other code if the expression is false (0). If the tested expression is true, codes inside the body of the if statement is executed and, codes inside the

Array in C Programming | C Programming

Image
Array in C Array in C Programming The C language provides a capability that enables the user to define a set of ordered data items known as an array. Suppose we had a set of grades that we wished to read into the computer and suppose we wished to perform some operations on these grades, we will quickly realize that we cannot perform such an operation until each and every grade has been entered since it would be quite a tedious task to declare each and every student grade as a variable especially since there may be a very large number. In C we can define a variable called grade, which represents not a single value of grade but an entire set of grades. Each element of the set can then be referenced by means of a number called an index number or subscript. Declaration of arrays Like any other variable arrays must be declared before they are used. The general form of declaration is: type variable-name [50]; The type specifies the type of the elements that will be contained in the array,

Constant in C Programming | C Programming

Constants in C Programming Constants in C refer to fixed values that do not change during the execution of a program.  const  is the keyword and it’s used to declare constants. A constant value is one that does not change during the execution of a program. C supports several types of constants. Integer Constants Real Constants Single Character Constants String Constants A constant value is one that does not change during the execution of a program. C supports several types of constants. Integer Constants Real Constants Single Character Constants String Constants Integer Constants: An integer constant is a sequence of digits. There are 3 types of integers namely decimal integers, octal integers, and hexadecimal integers. Decimal Integers: Consists of a set of digits 0 to 9 preceded by an optional + or - sign. Spaces, commas, and non-digit characters are not permitted between digits. Examples of valid decimal integer constant are: 123 -31 0 562321 + 78 Some examples

Expression, Statements and Comments in C Programming | C Programming

Image
Expression, Statements, and Comments in C Programming  Arithmetic C Expressions in C Programming An expression is a combination of variables constants and operators written according to the syntax of the C language. In C every expression evaluates to a value i.e., every expression results in some value of a certain type that can be assigned to a variable. Some examples of C expressions are shown in the table given below. Algebraic C Expression in C programming Expression a x b - ca * b – c (m + n) (x + y) (m + n) * (x + y) (ab / c)a * b / c 3x2 +2x + 13*x*x+2*x+1 (x / y) + cx / y + c Evaluation of Expressions in C Programming Expressions are evaluated using an assignment statement of the form Variable = expression; Variable is any valid C variable name. When the statement is encountered, the expression is evaluated first and then replaces the previous value of the variable on the left-hand side. All variables used in the expression must be assigned values before evaluation

Variables in C

Image
Variables in C Programmings:- "Variable in C" variables names are case sensitive whose value can change any time. It is a memory location used to store data value. A variable name in C variables should be carefully chosen so that its use is reflected in a useful way in the entire program.  Rules for declaring variables in C Programming:- They must always begin with a letter, although some systems permit underscore as the first character. The length of a variable must not be more than 8 characters. White space is not allowed and A variable should not be a Keyword It should not contain any special characters.  In C variables A variable declaration provides assurance to the compiler that there exists a variable with the given type and name so that the compiler can proceed for further compilation without requiring the complete detail about the variable. A variable definition has its meaning at the time of compilation only, the compiler needs actual variable

Structure In C Programming | C Programming

Structure In C Programming    Arrays are used to store large set of data and manipulate them but the disadvantage is that all the elements stored in an array are to be of the same data type. If we need to use a collection of different data type items it is not possible using an array. When we require using a collection of different data items of different data types we can use a structure.  Structure is a method of grouping data of different types.  A structure is a convenient method of handling a group of related data items of different data types.  

String In C Programming | C Programming

String The way a group of integers can be stored in an integer array. Similarly, a group of characters can be stored in a character array. Character arrays are many a time also called strings. Many languages internally treat strings as character arrays, but somehow conceal this fact from the programmer. Character arrays or strings are used by programming languages to manipulate text such as words and sentences. A string constant is a one-dimensional array of characters terminated by a null (‘\0’).  For example, char name [ ] = { 'H' , 'A' , 'E' , 'S' , 'L' , 'E' , 'R' , ' \0 ' } ; Each character in the array occupies one byte of memory and the last character is always ‘\0’. What character is this? It looks like two characters, but it is actually only one character, with the \ indicating that what follows it is something special. ‘\0’ is called a null character. Note that ‘\0’ and ‘0’ are not the same. The ASCII value

Global Variable in C Programming | C Programming

Global Variable in C Programming   A local variable is one that is declared inside a function and can only be used by that function. If you declare a variable outside all functions then it is a global variable and can be used by all functions in a program.             // Global variables     int a;     int b;      int Add()     {        return a + b;     }      int main()     {     // Local variable          a = 5;          b = 7;         answer = Add();          printf("%d\n",answer);         return 0;     }        Call by Value and Call by reference       The arguments passed to function can be of two types namely     1. Values passed / Call by Value     2. Address passed / Call by reference     The first type refers to call by value and the second type refers to call by reference.      For instance, consider program 1:              main()            {                    int x=50, y=70;                      inter

Functions and Array in C Programming | C Programming

Functions and Array in C Programming We can pass an entire array of values into a function just as we pass individual variables. In this task it is essential to list the name of the array along with functions arguments without any subscripts and the size of the array as arguments      For example:    Largest(a,n);    will pass all the elements contained in the array a of size n. the called function expecting this call must  be appropriately defined. The largest function header might look like:      float smallest(array,size);    float array[];    int size;  The function smallest is defined to take two arguments, the name of the array and the size of the array  to specify the number of elements in the array. The declaration of the formal argument array is made as  follows:       float array[ ];      The above declaration indicates to compiler that the arguments array is an array of numbers. It is not  necessary to declare size of the array here. While dealing with array

GO TO Statement in C Programming | C Programming

Image
GO TO Statement in C Programming     The goto statement is simple statement used to transfer the program control unconditionally from one    statement to another statement. Although it might not be essential to use the goto statement in a highly    structured language like C, there may be occasions when the use of goto is desirable.        Syntax               a> b>                goto label; label:              ………… …………              ………… …………              ………… …………              Label: goto label;              Statement;         The goto requires a label in order to identify the place where the branch is to be made. A label is a valid variable name followed by a colon. The label is placed immediately before the statement where the control is to be transformed. A program may contain several goto statements that transferred to the same place when a program. The label must be unique.  Control can be transferred out of or within a compound statement

If statements in C Programming | C Programming

Image
If statements in C Programming The different form of  if statements  with their syntax and semantic diagram are:- if statements:-                            The if statement evalutes the test expression inside the parenthesis. If the test expression is evaluated to true(non zero), statements inside the body of it is executed. If the test ecpression is evaluated to false(0), statements inside the body of if is skipped from execution. The Syntax and Sementics diagram is : if (test expression) {(statements) }                                                                                                               if else statement:                                 The if else statement executes some code if the test expression is true (nonzero) and some other code if the expression is false(0). If tested expression is true, codes inside the body of if statement is executed and, codes inside the body of else is skipped. And when it is false codes inside the bo

Switch Statement in C Programming | C Programming

Switch Statement in C Programming      Unlike the If statement which allows a selection of two alternatives the switch statement allows a    program to select one statement for execution out of a set of alternatives. During the execution of the    switch statement only one of the possible statements will be executed the remaining statements will be    skipped. The usage of multiple If else statement increases the complexity of the program since when the number of If else statements increase it affects the readability of the program and makes it difficult to follow the program. The switch statement removes these disadvantages by using a simple and straight forward approach.        The general format of the Switch Statement is                    Switch (expression)                  {                          case case-label-1:     statement;    break;                        case case-label-2:    statement;     break;  …   …   …                        case case-label-n:     statement;   

Operators in C Programming and Its Types | C Programming Language

Image
Operators in C Programming: - An operator in general is a symbol that operates on a certain data types. An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. The types of operators are: - Arithmetic Operators in C Programming-:              The arithmetic operators performs arithematic operations. The arithmetic operator is given below:- (+) - Addition (-) -Subtraction (*)- Multiplication (/)- Division (%) - Modulo Division   Relational operators in C Programming:-             Relational operators are used to compare logical, arithmetic and character expression. A list of relational operators is give below:- (<)             Less than (>)            Greater than (< =)          Less than or equal to (> =)         Greater than or equal to (==)              Equal to (! =)              Not equal to Logical Operators in C Programming: -             An expression logical operator retur