Tuesday, 21 June 2016

Best Tutorials On c:part-2

                                                                                  9.Strings or Character Arrays


10. Pointers


11. Structures & Unions



12. File Management




Thursday, 26 May 2016

Best Tutorials On c:part-1


1. Overview of C Language
  

2.  constant, variable & data type in c

                                   3.Operator and Expressions (Arithmetic, Logical, Relational )

                                                    4. Input Output (printf, scanf, format specifiers)


                                                 

                                             4.Decision making & branching         

                                                            


                                             5.Decision making & Looping


                                              

                                                 


6.Recursion 


                                                              

7.Preprocessor(Macro)


8.Array










C VIVA QUESTIONS & ANSWERS

C VIVA Q&A

1.Who developed C language?
C language was developed by Dennis Richie in 1970 at Bell Laboratories.

2.Which type of language is C?
C is a high – level language and general purpose structured programming language.

3.What is a compiler?
Compile is a software program that transfer program developed in high level language into executable object code

4.What is IDE?
The process of editing, compiling, running and debugging is managed by a single integrated application known as Integrated Development Environment (IDE)

5.What is a program?
A computer program is a collection of the instructions necessary to solve a specific problem.

6.What is an algorithm?
The approach or method that is used to solve the problem is known as algorithm.

7.What is structure of C program?
A C program contains Documentation section, Link section, Definition section, Global declaration section, Main function and other user defined functions

8.What is a C token and types of C tokens?
The smallest individual units are known as C tokens. C has six types of tokens Keywords,Constants, Identifiers, Strings, Operators and Special symbols.

9.What is a Keyword?
Keywords are building blocks for program statements and have fixed meanings and these meanings cannot be changed.

10.How many Keywords (reserve words) are in C?
There are 32 Keywords in C language.
11.What is an Identifier?
Identifiers are user-defined names given to variables, functions and arrays.

12.What is a Constant and types of constants in C?
Constants are fixed values that do not change during the program execution. Types of constants are Numeric Constants (Integer and Real) and Character Constants (Single Character, String Constants).

13.What are the Back Slash character constants or Escape sequence characters available in C?
Back Slash character constant are \t, \n, \0

14.What is a variable?
Variables are user-defined names given to memory locations and are used to store values. Avariable may have different values at different times during program execution

15.What are the Data Types present in C?
Primary or Fundamental Data types (int, float, char), Derived Data types(arrays, pointers)and User-Defined data types(structures, unions, enum)

16.How to declare a variable?
The syntax for declaring variable is data type variable_name-1, variable_name-2,....variable_name-n;

17.What is meant by initialization and how we initialize a variable?
While declaring a variable assigning value is known as initialization. Variable can be initialized by using assignment operator (=).

18.What are integer variable, floating-point variable and character variable?
A variable which stores integer constants are called integer variable. A variable which stores real values are called floating-point variable. A variable which stores character constants are called character variables.

19.How many types of operator or there in C?
C consist Arithmetic Operators (+, -, *, /,%), Relational Operators (<, <=, >, >=, !=), Logical Operators (&&, ||, !), Assignment Operators (=, +=, -=, *=, /=), Increment and Decrements operators (++, --), Conditional Operator(?:), Bit wise Operators(<<, >>, ~, &, |, ^) and Special Operators (. , ->, &, *, sizeof)

20.What is a Unary operator and what are the unary operators present in C?
An operator which takes only one operand is called unary operator. 
C unary operators are Unary plus (+), Unary minus (-), Increment and Decrements operators (++,--), Address of operator (&), Value at operator (*), sizeof operator, ones complement operator (~).

21.What is a ternary operator and which is called ternary operator is C?
An operator which takes three operands is called ternary operator. Conditional operator (? :)is knows as ternary operator in C.

22.What is the use of modulus (%) operator?
The modulus operator produces the remainder of an integer division. It cannot be used on floating point data.

23.What is the use of printf and scanf functions in C?
Values of variables and results of expressions c

*What is the use of printf and scanf functions in C?Values of variables and results of expressions can be displayed on the screen using printf functions. Values to variables can be accepted through the keyboard using scanf function.

24.What are the format codes used in printf and scanf functions in C?
%c (for reading or printing a single character), %d (for reading or printing signed integer),%u (for reading or printing unsigned integer), %ld (for reading or printing long signed integer), %lu (for reading or printing long unsigned integer), %f (for reading or printing floating point value), %lf (for reading or printing double floating point value), %Lf (for reading or printing long double value, %s (for reading or printing string value)

25.What are the decision making statements available in C?
IF statement, Switch statement and conditional statement

26.What is the use of IF statement and how it works?
The IF statement is used to control the flow of execution of statements. It first evaluates the given expression and then, depending on whether the value of the expression is true or false, it transfers the control to a particular statement.

27.Forms of IF statements?
Simple IF statement, IF-ELSE statement, NESTED IF-ELSE statement and ELSE IF ladder

28.How switch statement works?
The switch statement tests the value of a given variable against a list of case values and when a match is found, block of statement associated with that case is executed and if no match is found then the block of statements associated with the optional default is executed. If default case not present, control goes to the statement after the switch.

29.What is the difference between IF and SWITCH statement?
IF works on integers, floats and characters whereas SWITCH works on only integers and characters. Switch statement cannot perform inequality comparisons whereas IF can perform both equality and inequality comparisons.

30.How conditional operator (? :) works?
The conditional expression is evaluated first. If the expression is true then expression after the question mark is executed otherwise expression after the colon is executed

31.What is GOTO statement?
GOTO is an unconditional branching statement which transfer control to the specified label

32.What is a LOOP?Loop is a sequence of statements that are executed repeatedly.

33.What are the types of LOOP control statement?
Entry-Controlled Loop statement and Exit-Controlled loop statement

34.What are the LOOP control statements present in C?
WHILE, DO-WHILE, FOR

35.What are the sections present in FOR loop?
Initialization section, Conditional section, increment or decrements section

36.How a FOR loop works?
In FOR loop first initialization section is executed, then given condition is checked. If condition becomes true then body of the loop is executed after that increment or decrements section is executed

37.What is the use of break statement?
Break statement is used to exit from a loop

38.What is an ARRAY?
Array is a collective name given to similar elements

39.How ARRAY elements are stored in memory?
Array elements are stored in consecutive memory locations

40.How we can initialize an ARRAY?
All the element are separated by comma and enclosed within braces

41.How to access array element?
Array elements can be accessed by using subscript

42.What is the difference between normal variable and array variable?
A variable can store only one value at a time whereas array variable can store several value at a time.

43.What are the types of Array’s?
One-Dimensional array, Two-Dimensional array and Multi-Dimensional array.

44.What is a TWO-DIMENSIONAL array?
Matrix are generally known as TWO-DIMENSIONAL array .

45.What is a character array?
Array which can store several characters is called character array.

46.How to initialize a character array?
Character arrays can be initialized by separating character constants with comma and enclosed with in parenthesis or characters enclosed within double.

47.What is the difference between reading strings using scanf and gets?
Scanf can not read strings with multiple words whereas gets can read strings with multiple words.

48.What are the String-Handling functions available in C?
gets, puts, strcat, strcmp, strcpy and strlen.

49.What are the types of functions?
C functions are divided into two categories user-defined function and built-in functions

50.What is a function?
Function is a self contained block of statement which is used to perform certain task.

51.Which are called built-in functions?
Printf, scanf, clrscr, gotoxy, string handling functions and file handling functions.

52.What is function prototype declaration?
A function declaration is also known as function prototype declaration which contains function return type, function name, parameter list and terminating semicolon.

53.What are formal arguments and actual arguments?
Arguments that are used in function calling are called actual arguments. Arguments that are used in function definition are called formal arguments.

54.What is a recursive function?
A function calling itself is called function recursion.

55.What is call by value and call by reference?
Passing values to the called function is called call by value, passing addresses to the called function is called call by reference.

56.How to pass an array to a function?
Arrays are passed to a function by sending its address.

57.What is a global variable and local variable?
Variables which are declared in the global section is called global variables and Variables which are declared in a function or a block are called local variables.

58.What is a pointer variable?
Pointer variable is a variable which can store address of another variable.

59.How can we store address of a variable in a pointer?
By using address of operator we can store address of a variable in a pointer.

60.How can we access a variable value using a pointer?
By using value at operator we can access a variable value using its pointer.

61.What is the use of pointers?
Pointer are used to pass array and structures from function to another function.

62.How many bytes a pointer variable occupies in memory?
A pointer variable irrespective of its type it occupies two bytes in memory.

63.What are the storage classes available in C?
Auto, Static, Extern and Register.

64.What is a structure?
Structure is a user-defined data type. Structure is a collective name given to dissimilar elements.
                                       
                                                                                  ~: BLOG OF GOPAL BASAK :~

Sunday, 15 May 2016

Control Statement & Description

Decision making structures require that the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
Show below is the general form of a typical decision making structure found in most of the programming languages −
Decision making statements in C
C programming language assumes any non-zero and non-null values as true, and if it is either zero or null, then it is assumed as false value.
C programming language provides the following types of decision making statements.
S.N.Statement & Description
1if statement
An if statement consists of a boolean expression followed by one or more statements.
2if...else statement
An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.
3nested if statements
You can use one if or else if statement inside another if or else ifstatement(s).
4switch statement
switch statement allows a variable to be tested for equality against a list of values.
5nested switch statements
You can use one switch statement inside another switchstatement(s).

The ? : Operator

We have covered conditional operator ? : in the previous chapter which can be used to replace if...else statements. It has the following general form −
Exp1 ? Exp2 : Exp3;
Where Exp1, Exp2, and Exp3 are expressions. Notice the use and placement of the colon.
The value of a ? expression is determined like this −
  • Exp1 is evaluated. If it is true, then Exp2 is evaluated and becomes the value of the entire ? expression.
  • If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the expression.

    C-Loops

You may encounter situations, when a block of code needs to be executed several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.
Programming languages provide various control structures that allow for more complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple times. Given below is the general form of a loop statement in most of the programming languages −
Loop Architecture
C programming language provides the following types of loops to handle looping requirements.
S.N.Loop Type & Description
1while loop
Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.
2for loop
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
3do...while loop
It is more like a while statement, except that it tests the condition at the end of the loop body.
4nested loops
You can use one or more loops inside any other while, for, or do..while loop.

Loop Control Statements

Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.
C supports the following control statements.
S.N.Control Statement & Description
1break statement
Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.
2continue statement
Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
3goto statement
Transfers control to the labeled statement.
To know about the statements & loops click on that .

Loop Control Statements

Break Statesmen in C

The break statement in C programming has the following two usages −
  • When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
  • It can be used to terminate a case in the switch statement (covered in the next chapter).
If you are using nested loops, the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.

Syntax

The syntax for a break statement in C is as follows −
break;

Flow Diagram

c break statement

Example

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 10;

   /* while loop execution */
   while( a < 20 ) {
   
      printf("value of a: %d\n", a);
      a++;
  
      if( a > 15) {
         /* terminate the loop using break statement */
         break;
      }
  
   }
 
   return 0;
}
When the above code is compiled and executed, it produces the following result −
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15

Continue Statement in C

The continue statement in C programming works somewhat like the breakstatement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between.
For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops,continue statement causes the program control to pass to the conditional tests.

Syntax

The syntax for a continue statement in C is as follows −
continue;

Flow Diagram

C continue statement

Example

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 10;

   /* do loop execution */
   do {
   
      if( a == 15) {
         /* skip the iteration */
         a = a + 1;
         continue;
      }
  
      printf("value of a: %d\n", a);
      a++;
     
   } while( a < 20 );
 
   return 0;
}
When the above code is compiled and executed, it produces the following result −
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19

Goto Statement in C

goto statement in C programming provides an unconditional jump from the 'goto' to a labeled statement in the same function.
NOTE − Use of goto statement is highly discouraged in any programming language because it makes difficult to trace the control flow of a program, making the program hard to understand and hard to modify. Any program that uses a goto can be rewritten to avoid them.

Syntax

The syntax for a goto statement in C is as follows −
goto label;
..
.
label: statement;
Here label can be any plain text except C keyword and it can be set anywhere in the C program above or below to goto statement.

Flow Diagram

C goto statement

Example

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 10;

   /* do loop execution */
   LOOP:do {
   
      if( a == 15) {
         /* skip the iteration */
         a = a + 1;
         goto LOOP;
      }
  
      printf("value of a: %d\n", a);
      a++;
     
   }while( a < 20 );
 
   return 0;
}
When the above code is compiled and executed, it produces the following result −
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19

Recent Post

C videos in Hindi language

Hello friends , in the following links you will get whole C Programming videos in Hindi Language (availability is not guaranteed & th...

Popular Posts

visit counter