techpreparation-homepage

Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog

  C Programming Tutorials
Basics of C:
Facts about C
Why to Use C
C Program File
C Compilers

Program Structure:
Simple C Program
C Program Compilation

Basic DataTypes:
DataTypes
Modifiers
Qualifiers
Arrays

Variable Types:
Local Variable
Global Variable

Storage Classes:
auto storage class
register storage class
static storage class
extern storage class

Using Constants:
Defining Constants
The enum Data Types

Operator Types:
Arithmetic Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators

Control Statements:
Branching
Looping

Input and Output:
printf() function
scanf() function

Pointing to Data:
Pointers and Arrays
Pointer Arithmetic
Pointer Arithmetic with arrays

Functions:
Using functions
Declaration and Definition

Strings:
Reading and Writing Strings
String Manipulation Function

Structured DataTypes:
Structure
Pointer to Structure

Working with Files:
Files
Basic I/O

Bits:
Bits Manipulation
Bits Field

Pre-Processors:
Pre-Processors Examples
Parameterized Macros
Macro Caveats

Useful Concepts

Built-in Library Functions:
String Manipulation Function
Memory Management Function
Buffer Manipulation
Character Functions
Error Handling Functions

Soft Skills
Communication Skills
Leadership Skills
                              .........More

 

 

  

C Programming Tutorials


Looping
Loops provide a way to repeat commands and control how many times they are repeated. C provides a number of looping way.

while loop
The most basic loop in C is the while loop. A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statements get executed. The difference is that after the statements have been executed, the test condition is checked again. If it is still true the statements get executed again. This cycle repeats until the test condition evaluates to false.

Basic syntax of while loop is as follows:
Show Example

while ( expression )
{
Single statement
or
Block of statements;
}

for loop
for loop is similar to while, it's just written differently. for statements are often used to process lists such a range of numbers:

Basic syntax of for loop is as follows:
Show Example

for( expression1; expression2; expression3)
{
Single statement
or
Block of statements;
}

In the above syntax:

  • expression1 - Initializes variables.

  • expression2 - Conditional expression, as long as this condition is true, loop will keep executing.

  • expression3 - expression3 is the modifier which may be simple increment of a variable.

do...while loop
do ... while is just like a while loop except that the test condition is checked at the end of the loop rather than the start. This has the effect that the content of the loop are always executed at least once.

Basic syntax of do...while loop is as follows:
Show Example

do
{
Single statement
or
Block of statements;
}while(expression);

break and continue statements
C provides two commands to control how we loop:

  • break -- exit form loop or switch.

  • continue -- skip 1 iteration of loop.

You already have seen example of using break statement. Here is an example showing usage of continue statement.

#include

main()
{
int i;
int j = 10;

for( i = 0; i <= j; i ++ )
{
if( i == 5 )
{
continue;
}
printf("Hello %d\n", i );
}
}

This will produce following output:

Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 6
Hello 7
Hello 8
Hello 9
Hello 10

NEXT >> Input and Output

Have a Question ? post your questions here. It will be answered as soon as possible.

Check C Aptitude Questions for more C Aptitude Interview Questions with Answers

Check C Interview Questions for more C Interview Questions with Answers