C Imp Notes
C Imp Notes
while do-while
Variable in condition is initialized before the variable may be initialized before or within the
execution of loop. loop.
while loop is entry controlled loop. do-while loop is exit controlled loop.
while(condition) do { statement(s); }
{ statement(s); } while(condition);
The Break statement is used to exit from the loop The continue statement is not used to exit from
constructs. the loop constructs.
The break statement is usually used with the switch The continue statement is not used with the switch
statement, and it can also use it within the while statement, but it can be used within the while
loop, do-while loop, or the for-loop. loop, do-while loop, or for-loop.
When a break statement is encountered then the When the continue statement is encountered then
control is exited from the loop construct the control automatically passed to the beginning
immediately. of the loop statement.
Break Statement Continue Statement
Syntax: Syntax:
break; continue;
Break statements uses switch and label statements. It does not use switch and label statements.
Definition: Arrays are contiguous ordered sequences of elements, while strings are defined as "a
contiguous sequence of characters terminated by and including the first null character
Data Type: Arrays have a specific data type, while strings are a data layout.
Representation: Strings are represented as arrays of characters, with the final character being a null
character.
Termination: Strings are terminated with a null character, while arrays do not have this require
What is Array in C?
An array in C is a fixed-size collection of similar data items stored in contiguous memory locations. It
can be used to store the collection of primitive data types such as int, char, float, etc.
In this method, we initialize the array along with its declaration. We use an initializer list to initialize
multiple elements of the array. An initializer list is the list of values enclosed within braces {
} separated b a comma.
Types of Array in C
There are two types of arrays based on the number of dimensions it has. They are as follows:
Advantages :
It is convenient way of storing the data of same datatype with same size.
It does not allocate any extra space/ memory for its elements
It allows to store the elements in any dimensional array – supports multidimensional array.
String in C?
The difference between a character array and a C string is that the string in C is terminated with a
unique character ‘\0’.
Declaring a string in C is as simple as declaring a one-dimensional array. Below is the basic syntax for
declaring a string.
char string_name[size];
The C language comes bundled with <string.h> which contains some useful string-handling
functions. Some of them are as follows:
Compares the first string with the second string. If strings are the same
strcmp(str1, str2)
it returns 0.
strcat(s1, s2) Concat s1 string with s2 string and the result is stored in the first string.