0% found this document useful (0 votes)
6 views3 pages

C Imp Notes

Uploaded by

ridashaikh215
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

C Imp Notes

Uploaded by

ridashaikh215
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C Imp Notes

Difference between while and do while loop

while do-while

Condition is checked first then statement(s) is Statement(s) is executed atleast once,


executed. thereafter condition is checked.

It might occur statement(s) is executed zero


At least once the statement(s) is executed.
times, If condition is false.

No semicolon at the end of while. Semicolon at the end of while.


while(condition) while(condition);

If there is a single statement, brackets are not


Brackets are always required.
required.

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);

Break Statement Continue Statement

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.

Differences between arrays and strings in C:

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.

Syntax of Array Declaration

data_type array_name [size];

Array Initialization with Declaration

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.

data_type array_name [size] = {value1, value2, ... valueN};

Types of Array in C

There are two types of arrays based on the number of dimensions it has. They are as follows:

 One Dimensional Arrays (1D Array)


 Multidimensional Arrays

Advantages :

 It is convenient way of storing the data of same datatype with same size.

 It allows us to store known number of elements in it.


 It allocates memory in contiguous memory locations for its elements.

 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?

A String in C programming is a sequence of characters terminated with a null character ‘\0’.

The C String is stored as an array of characters.

The difference between a character array and a C string is that the string in C is terminated with a
unique character ‘\0’.

C String Declaration Syntax

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];

Standard C Library – String.h Functions

The C language comes bundled with <string.h> which contains some useful string-handling
functions. Some of them are as follows:

Function Name Description

strlen(string_name) Returns the length of string name.

strcpy(s1, s2) Copies the contents of string s2 to string s1.

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.

strlwr() Converts string to lowercase.

strupr() Converts string to uppercase.

You might also like