Posts

C - 2D Array

Image
 Two dimensional arrays : Two dimensional array is known as matrix. The array declaration in both the array i.e.in single dimensional array single subscript is used and in two dimensional array two subscripts are is used.  Its syntax is  Data-type array name[row][column];  Or we can say 2-d array is a collection of 1-D array placed one below the other. Total no. of elements in 2-D array is calculated as row*column  Example:-   int a[2][3];   Total no of elements=row*column is 2*3 =6  It means the matrix consist of 2 rows and 3 columns  For example:-   20        2        7    8         3       15  Positions of 2-D array elements in an array are as below  00       01       02  10       11       12  Accessing 2-d array /processing 2-d...

C - Array

 Array Array is the collection of similar data types or collection of similar entity stored in contiguous memory location. Array of character is a string. Each data item of an array is called an element. And each element is unique and located in separated memory location. Each of elements of an array share a variable but each element having different index no. known as subscript.  An array can be a single dimensional or multi-dimensional and number of subscripts determines its dimension. And number of subscript is always starts with zero. One dimensional array is known as vector and two dimensional arrays are known as matrix.  ADVANTAGES: array variable can store more than one value at a time where other variable can store one value at a time.  Example:   int arr[100]; int mark[100]; DECLARATION OF AN ARRAY :   Its syntax is :   Data type array name [size];   int arr[100];   int mark[100];  int a[5]={10,20,30,10...

C - break and continue

 Break and Continue: Break Vs Continue break continue A  break  can appear in both  switch  and loop ( for ,  while ,  do ) statements. A  continue  can appear only in loop ( for ,  while ,  do ) statements. A  break  causes the  switch  or loop statements to terminate the moment it is executed. Loop or  switch  ends abruptly when break is encountered. A  continue  doesn't terminate the loop, it causes the loop to go to the next iteration. All iterations of the loop are executed even if  continue  is encountered. The  continue  statement is used to skip statements in the loop that appear after the  continue . The  break  statement can be used in both  switch  and loop statements. The  continue  statement can appear only in loops. You will get an error if this appears in switch statement. When a  break  statement is encountered, i...

C - Loops

 Loops in C: Loop:-it is a block of statement that performs set of instructions. In loops Repeating particular portion of the program either a specified number of time or until a particular no of condition is being satisfied.  There are three types of loops in c  1.While loop  2.do while loop  3.for loop   While loop: Syntax:-  while(condition)  {  Statement 1;  Statement 2;  }  Or  while(test condition)  Statement;  The test condition may be any expression .when we want to do something a fixed no of times but not known about the number of iteration, in a program then while loop is used.  Here first condition is checked if, it is true body of the loop is executed else, If condition is false control will be come out of loop.  Example:-  /* wap to print 5 times welcome to C” */   #include  <stdio.h> void main()  {  int p=1;  While(p<=5)  {  printf(“Welcome ...

C - Conditional Statement

 Control Statement: Generally C program statement is executed in a order in which they appear in the program. But sometimes we use decision making condition for execution only a part of program, that is called control statement. Control statement defined how the control is transferred from one part to the other part of the program. There are several control statement like if...else, switch, while, do....while, for loop, break, continue, goto etc. if statement:  Statement execute set of command like when condition is true and its syntax is   If (condition)   Statement;  The statement is executed only when condition is true. If the if statement body is consists of several statement then better to use pair of curly braces. Here in case condition is false then compiler skip the line within the if block.  void main()  {   int n;   printf (“ enter a number:”);   scanf(“%d”,&n); If (n>10)   Printf...

C - Operator

 Operators: This is a symbol use to perform some operation on variables, operands or with the constant. Some operator required 2 operand to perform operation or Some required single operation.  Several operators are there those are, arithmetic operator, assignment, increment , decrement, logical, conditional, comma, size of , bitwise and others.   1. Arithmatic Operator: This operator used for numeric calculation. These are of either Unary arithmetic operator, Binary arithmetic operator. Where Unary arithmetic operator required only one operand such as +,-, ++, --,!, tiled. And these operators are addition, subtraction, multiplication, division. Binary arithmetic operator on other hand required two operand and its operators are +(addition), -(subtraction), *(multiplication), /(division), %(modulus). But modulus cannot applied with floating point operand as well as there are no exponent operator in c. Unary (+) and Unary (-) is different from addition and subtrac...

C - Constants and Variables

Image
 Constants And Variable Constants: Constant is a any value that cannot be changed during program execution. In C, any number, single character, or character string is known as a constant. A constant is an entity that doesn’t change whereas a variable is an entity that may change. For example, the number 50 represents a constant integer value. The character string "Programming in C is fun." is an example of a constant character string. C constants can be divided into two major categories:  Primary Constants  Secondary Constants  These constants are further categorized as    Numeric constant   Character constant   String constant Numeric constant:   Numeric constant consists of digits. It required minimum size of 2 bytes and max 4 bytes. It may be positive or negative but by default sign is always positive. No comma or space is allowed within the numeric constant and it must have at least 1 digit. The allowable range for integer const...