<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Three2Tango &#187; C and C++</title>
	<atom:link href="http://www.three2tango.com/category/techcorner/c-and-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.three2tango.com</link>
	<description>Points To Ponder : The Latest news from the TechWorld,Automobiles,CellPhones and lots of useful Code Snippets</description>
	<lastBuildDate>Fri, 27 Jan 2012 09:03:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Data Files</title>
		<link>http://www.three2tango.com/techcorner/data-files.html/</link>
		<comments>http://www.three2tango.com/techcorner/data-files.html/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 09:34:18 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[C programs]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2533</guid>
		<description><![CDATA[
Data stored in program variables and arrays are temporary in nature. Such data is normally stored in the main memory(RAM) of the computer and it will be lost when the program. The best way to work with or process a large data is to store that data permanently in the computer&#8217;s memory.
To store data permanently we can use the secondary storage devices such as hard disks and magnetic tapes.
The data stored on the secondary storage devices is viewed as the data files.

File

A data file(or simply file) is a collection of ...]]></description>
			<content:encoded><![CDATA[<ul>
<li>Data stored in program variables and arrays are temporary in nature. Such data is normally stored in the main memory(RAM) of the computer and it will be lost when the program. The best way to work with or process a large data is to store that data permanently in the computer&#8217;s memory.</li>
<li>To store data permanently we can use the secondary storage devices such as hard disks and magnetic tapes.</li>
<li>The data stored on the secondary storage devices is viewed as the <strong>data files</strong>.</li>
</ul>
<p><strong>File</strong></p>
<ul>
<li>A data file(or simply file) is a collection of logically related information.</li>
<li>Data files can be accessed for the purpose of reading data from them and writing data back into them.</li>
<li>The data read from the files are assigned to the variables in the program and similarly, the values of variables from the source program are written into the files.</li>
<li>There are two ways in which the data files are accessed for either reading data from or writing data into them. They are :</li>
</ul>
<ol>
<li>Sequential Access(or linear) &#8211; from beginning to end of file.</li>
<li>Random Access(or direct) &#8211; directly pointing to the specified location in a file.</li>
</ol>
<p><strong>File Declaration</strong></p>
<ul>
<li>Any file that is accessed for reading or writing purpose must be declared.</li>
<li>The syntax &#8211; FILE *pointer_to_file;</li>
</ul>
<p><strong>Opening a File</strong></p>
<ul>
<li>Before performing any operation, a data file must be opened.</li>
<li>The function fopen() is used for opening a file.</li>
<li>On Success, fopen() returns a file pointer. Otherwise, it returns NULL.</li>
</ul>
<p><strong>Access Modes</strong></p>
<ul>
<li>File access modes indicate the purpose of the file being opened.</li>
<li>A file can be opened for reading data from a file or for writing data into a file. Sometimes we may be adding data to the end of the already existing file.</li>
</ul>
<table border="1">
<tbody>
<tr>
<th>Access Mode</th>
<th>Status</th>
</tr>
<tr>
<td>w &#8211; Write-only mode</td>
<td>The file is opened for writing. The file is created if it is not existing. If the file is already existing, then the earlier contents are overwritten.</td>
</tr>
<tr>
<td>r &#8211; Read-only mode</td>
<td>The file is opened for reading. If the file does not exist then we can not open it for reading.</td>
</tr>
<tr>
<td>a &#8211; Append mode</td>
<td>The file is opened for appending. That is, the file already exists, and it may have some content. When a file is opened in this mode, the file pointer points to the end of the file.</td>
</tr>
<tr>
<td>w+ &#8211; Read-Write mode</td>
<td>The file is opened for both reading and writing. It destorys the previous data stored in the file.</td>
</tr>
<tr>
<td>r+ &#8211; Write-Read mode</td>
<td>The file is opened for both reading and writing.</td>
</tr>
<tr>
<td>a+ &#8211; Append mode</td>
<td>The file is opened for reading and writing. However, data is written at the end of the file.</td>
</tr>
</tbody>
</table>
<p><strong>Closing a File</strong></p>
<ul>
<li>The files that are opened for reading or writing purpose must be closed.</li>
<li>The fclose() is used for closing a file.</li>
<li>int fclose(pointer_to_file);</li>
<li>This closes the file pointed to by the file pointer.</li>
<li>Once it is closed we can reuse the file pointer for opening other files.</li>
<li>On success, fclose() returns 0. Otherwise, it returns EOF(End of File) value.</li>
</ul>
<p><strong>Writing Data to Files</strong></p>
<ul>
<li><strong>fprintf()</strong> &#8211; to write the formatted data to the file.</li>
<li><strong>fputc()</strong> &#8211; to print a single character to the file.</li>
<li><strong>fputs()</strong> &#8211; to write a string(or array of characters) to the file.</li>
</ul>
<p><strong>Reading Data from Files</strong></p>
<ul>
<li><strong>fscanf()</strong> &#8211; to read the formatted data from the file.</li>
<li><strong>fgetc()</strong> &#8211; to read a single character from the file.</li>
<li><strong>fgets()</strong> &#8211; to read a string from the file.</li>
</ul>
<p><strong>Random Access Files</strong></p>
<ul>
<li>C provides a set of functions for writing or reading data to or from the data file randomly.</li>
<li><strong>fseek()</strong> &#8211; Repositions the file pointer of a stream.</li>
<li><strong>ftell()</strong> &#8211; Returns the current file pointer.</li>
<li><strong>rewind()</strong> &#8211; Takes the control back to the beginning of the file.</li>
</ul>
<ul>
<li><strong>fseek() function</strong> &#8211; The function fseek() sets the file pointer associated with a stream to a new position.</li>
<li>int fseek(FILE *stream, long offset, int where);</li>
<li>On success, the fseek() function (if the pointer is successfully moved) returns 0. On failure, fseek() returns a non-zero value.</li>
</ul>
<ul>
<li><strong>ftell() function</strong> &#8211; The ftell() function returns the current file pointer for stream.</li>
<li>long ftell(FILE *stream);</li>
<li>The value returned by ftell() can be used in a subsequent call to fseek()</li>
<li>On success, ftell() returns the current file pointer position. Otherwise, it returns -1L and sets errno(a variable indicating the type of error) to a positive value.</li>
</ul>
<p><a href="http://www.three2tango.com/techcorner/preprocessor-statements.html/">&lt;&lt;Previous Post</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/data-files.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preprocessor Statements</title>
		<link>http://www.three2tango.com/techcorner/preprocessor-statements.html/</link>
		<comments>http://www.three2tango.com/techcorner/preprocessor-statements.html/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 09:19:29 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[C programs]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2531</guid>
		<description><![CDATA[
Preprocessor &#8211; This is a macroprocessor that processes the source program before it is compiled. It is a collection of special statements called preprocesor statements or preprocessor directives.
These directives are executed before the C program passes through the compiler.


Preprocessor Directives &#8211; These are statements which begin with the # symbol placed in the first coloumn.
They are placed before the function main().
There will be no smicolon at the end of such statements.
Three types -


Macro substitution directives
File inclusion directives
Conditional compilation directives

Macro Substitution

This is a process of replacing an identifier of a C ...]]></description>
			<content:encoded><![CDATA[<ul>
<li><strong>Preprocessor</strong> &#8211; This is a macroprocessor that processes the source program before it is compiled. It is a collection of special statements called preprocesor statements or preprocessor directives.</li>
<li>These directives are executed before the C program passes through the compiler.</li>
</ul>
<ul>
<li><strong>Preprocessor Directives</strong> &#8211; These are statements which begin with the # symbol placed in the first coloumn.</li>
<li>They are placed before the function main().</li>
<li>There will be no smicolon at the end of such statements.</li>
<li>Three types -</li>
</ul>
<ol>
<li>Macro substitution directives</li>
<li>File inclusion directives</li>
<li>Conditional compilation directives</li>
</ol>
<p><strong>Macro Substitution</strong></p>
<ul>
<li>This is a process of replacing an identifier of a C program by a constant or a symolic constant.</li>
<li>This can be accomplished by the directive #define.</li>
</ul>
<p><strong>File Inclusion</strong></p>
<ul>
<li>This is a process of inserting the external files containing functions or macro definitions into a C program.</li>
<li>This process eliminates the job of rewriting the functions or macro definitions.</li>
</ul>
<p><strong>Conditional Compilation Directives</strong></p>
<ul>
<li>C preprocessor provides a conditional compilation directive which is used to select alternate segments of code in a C program depending upon the condition.</li>
<li>The #ifdef, #else, #elis, #endif directives are used for conditional compilation of the program. These are also used with the #define, #ifndef and #undef directives.</li>
</ul>
<p><a href="http://www.three2tango.com/techcorner/pointers.html/">&lt;&lt;Previous Post</a></p>
<p style="text-align: right;"><a href="http://www.three2tango.com/techcorner/data-files.html/">Next Post&gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/preprocessor-statements.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pointers</title>
		<link>http://www.three2tango.com/techcorner/pointers.html/</link>
		<comments>http://www.three2tango.com/techcorner/pointers.html/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 08:58:35 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[C programs]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2529</guid>
		<description><![CDATA[
To know where exactly the value of a variable is stored in the memory, you need to be aware of the concept called pointers.
A pointer is a powerful construct of the C programming language.
A pointer is a variable which holds the address of other variables such as arrays, structures and functions that are used in a program.
It contains only the memory location of the variable rather than its content.

Advantages

To point to different data structures.
Manipulation of data at different memory locations is easier.
To achieve clarity and simplicity.
More compact and efficient coding.
To ...]]></description>
			<content:encoded><![CDATA[<ul>
<li>To know where exactly the value of a variable is stored in the memory, you need to be aware of the concept called <strong>pointers</strong>.</li>
<li>A pointer is a powerful construct of the C programming language.</li>
<li>A pointer is a variable which holds the address of other variables such as arrays, structures and functions that are used in a program.</li>
<li>It contains only the memory location of the variable rather than its content.</li>
</ul>
<p><strong>Advantages</strong></p>
<ul>
<li>To point to different data structures.</li>
<li>Manipulation of data at different memory locations is easier.</li>
<li>To achieve clarity and simplicity.</li>
<li>More compact and efficient coding.</li>
<li>To return multiple values via functions.</li>
<li>Dynamic Memory Allocation.</li>
</ul>
<p><strong>Operations used with pointers</strong></p>
<ul>
<li>The address operator &#8211; &amp;(ampersand)</li>
<li>The indirection operator &#8211; *(asterix)</li>
<li>An address operator gives the address of a variable(not constants or expression); while the indirection operator gives the value of the variable that the pointer is pointing to.</li>
<li>Both the pointer variable and the variable to which pointer points to, must be declared.</li>
<li>Also, a pointer variable must be assigned the address of the declared variable before it is used in the program.</li>
</ul>
<p><strong>Pointer Dereferencing</strong></p>
<ul>
<li>This is a process of referencing the contents of the variables using pointers, indirectly.</li>
<li>Steps involved - Address of a variable, whose value is to be referenced is assigned to a pointer. Then, this pointer points to the value.</li>
</ul>
<p><strong>Operations on Pointers</strong></p>
<ul>
<li>A pointer variable holds the address of the other variables. This address can be incremented or decremented.</li>
<li>However, the pointer variables cannot be multiplied or divided.</li>
<li>A pointer variable can be assigned the address of other variable.</li>
<li>If two pointer variables are pointing to the object of the same data type, then they can be assigned.</li>
<li>A pointer variable can be assigned a NULL value(NULL = 0).</li>
<li>An integer value can be added to and subtracted from a pointer variable.</li>
<li>One pointer variable can be subtracted from another pointer variable, if both are pointing to the elements of the same array.</li>
<li>If two pointer variables are pointing to the objects of the same data type, then they can be compared with one another.</li>
</ul>
<p><strong>Pointer Initialization</strong></p>
<ul>
<li>As ordinary variables are initialized within the declaration part of a program, the pointer variables can also be initialized by assigning the addresses of another variables that are used in the program.</li>
<li>data_type *ptr_var = expression;</li>
<li>A pointer can also be initialized by assigning a NULL value.</li>
</ul>
<p><strong>Pointers and Functions</strong></p>
<ul>
<li>Like other parameters, pointers can also be passed to functions.</li>
<li>This is carried out by the call-by-reference parameter passing mechanism.</li>
</ul>
<p><strong>Call-by-Reference</strong></p>
<ul>
<li>This is a mechanism by which the pointers can be passed as arguements to the functions.</li>
<li>Thus, the data items of the calling program can be assessed by the called program(function).</li>
<li>No value is copied when the pointers are passed as arguements, as in the call-by-value method.</li>
<li>Another important point is that if the values are changed in the functions, this will modify the original contents of the original parameters.</li>
<li>In the calling program, the function is invoked with the function name and addresses of the actual parameters enclosed within the parantheses.</li>
<li>function_name(&amp;var1,&amp;var2,&#8230;&amp;varn);</li>
<li>In the parameter list of the called program each and every formal parameter(pointers) must be preceded by an indirection operator(*).</li>
<li>data_type function_name(*var1,*var2,&#8230;*varn);</li>
</ul>
<p><strong>Pointers and Arrays</strong></p>
<ul>
<li>Pointers can be used with arrays for efficient programming.</li>
<li><em>One-dimensional Arrays</em></li>
<li>The name of an array itself designates some memory location and that location in main memory is the address of the very first element of the array.</li>
<li>&amp;aarray[0] or simply array.</li>
<li>The addressof the i-th element of the array - &amp;array[i-1] or (array+(i-i))</li>
</ul>
<p><strong>Dynamic Memory Allocation</strong></p>
<ul>
<li>This is a process of dynamically allocating memory to any variable that is being used in your C program.</li>
<li>When the program is terminated, the dynamically allocated memory is deallocated.</li>
<li>malloc(), calloc(), free().</li>
<li>malloc() &#8211; This function is used to allocate the memory in bytes.</li>
<li>malloc(nob);</li>
<li>free() &#8211; This function frees a block of allocated memroy.</li>
<li>free(p);</li>
</ul>
<p><a href="http://www.three2tango.com/techcorner/structures-and-unions.html/">&lt;&lt;Previous Post</a></p>
<p style="text-align: right;"><a href="http://www.three2tango.com/techcorner/preprocessor-statements.html/">Next Post&gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/pointers.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Structures and Unions</title>
		<link>http://www.three2tango.com/techcorner/structures-and-unions.html/</link>
		<comments>http://www.three2tango.com/techcorner/structures-and-unions.html/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 01:26:07 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2459</guid>
		<description><![CDATA[
An array is used to store and process a group of homogeneous elements. But, to store and process eleents that are not homogeneous, the knowledge of the structure is required. Structures help in packing the disimilar data items under a single name.
A structure is a meaningful collection of data items of different type. But it collects all elements under a unique name. A structure allows the programmer to create and manipulate a set of different types of data items.
The keyword struct.


Each and every structure must be defined and declared before ...]]></description>
			<content:encoded><![CDATA[<ul>
<li>An array is used to store and process a group of homogeneous elements. But, to store and process eleents that are not homogeneous, the knowledge of <strong>the structure</strong> is required. Structures help in packing the disimilar data items under a single name.</li>
<li>A structure is a meaningful collection of data items of different type. But it collects all elements under a unique name. A structure allows the programmer to create and manipulate a set of different types of data items.</li>
<li>The keyword <strong>struct</strong>.</li>
</ul>
<ul>
<li>Each and every structure must be defined and declared before it appear in a C program.</li>
<li>The body of the structure is terminated by a semicolon.</li>
</ul>
<p>struct employee<br />
{<br />
int emp_code;<br />
char name[20];<br />
float salary;<br />
};</p>
<ul>
<li>The general form of declaring structure variables is :</li>
</ul>
<p>structure_type varlist;</p>
<ul>
<li>A structure within another structure is called an <strong>embedded structure</strong>.</li>
<li>A structure may completely be defined within the other structure.</li>
<li>There may be separate strucutres.The embedded structure is declared first and the other structure is declared next.</li>
<li>Like initialization of array elements, structure members can be initialized.</li>
<li>Each member of a structure is accessed with the <strong>dot operator</strong>.</li>
<li>The dot operator has the highest priority than any other operator of C, and it&#8217;s associativity is from left to right.</li>
</ul>
<ul>
<li>Whenever the same structure is to be applied to a group of people, items or applications we will have to use an <strong>array of structures</strong>.</li>
</ul>
<ul>
<li><strong>typedef</strong>(for type definition) statement &#8211; enables the programmer to define an alternate term to the basic data types.</li>
</ul>
<p>Syntax &#8211; typedef old_data_type new_data_type;</p>
<ul>
<li>A <strong>union</strong> is a collection of heterogeneous data elements. They are similar to structures.</li>
<li>However, there is a difference in the way the structure members and union members are stored. Each member within a structure is asigned its own memory location. But the union members, all share a common memory location. Thus, unions are used to save memory.</li>
<li>An inividual member of a union can be accessed using the dot operator or -&gt;(arrow) operator.</li>
</ul>
<p><a href="http://www.three2tango.com/techcorner/stringscharacter-arays.html/">&lt;&lt;Previous Post</a></p>
<p style="text-align: right;"><a href="http://www.three2tango.com/techcorner/pointers.html/">Next Post&gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/structures-and-unions.html/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Strings(Character Arays)</title>
		<link>http://www.three2tango.com/techcorner/stringscharacter-arays.html/</link>
		<comments>http://www.three2tango.com/techcorner/stringscharacter-arays.html/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 11:31:00 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2399</guid>
		<description><![CDATA[
A string is nothing but an array of characters.
Two strings can be compared, concatenated or copied. We can convert upper case letters into the lower case letters and vice-versa. Strings can be reversed. We can also check for the substrings present in the given string.


String is a one-dimensional array of characters.
Each one-dimensional character array(string) ends with a null character. So an n-character array contains (n+1) array elements.
C language provides many string handling functions which are defined in the header file .
Like a numeric array, character arrays must be declared before ...]]></description>
			<content:encoded><![CDATA[<ul>
<li>A <strong>string</strong> is nothing but an array of characters.</li>
<li>Two strings can be compared, concatenated or copied. We can convert upper case letters into the lower case letters and vice-versa. Strings can be reversed. We can also check for the substrings present in the given string.</li>
</ul>
<ul>
<li>String is a one-dimensional array of characters.</li>
<li>Each one-dimensional character array(string) ends with a null character. So an n-character array contains (n+1) array elements.</li>
<li>C language provides many string handling functions which are defined in the header file .</li>
<li>Like a numeric array, character arrays must be declared before they appear in a C program.</li>
<li>There is no change in the syntaxof declaring stings except the change in the data type(char).</li>
</ul>
<p><strong>Reading Strings</strong></p>
<ul>
<li> scanf() with the %s format specification</li>
<li>gets() function</li>
<li>getchar() funcation</li>
</ul>
<p><strong>Writing Strings</strong></p>
<ul>
<li> printf() with the %s format specification</li>
<li>puts() function</li>
<li>putchar() function</li>
</ul>
<ul>
<li>A <strong>two-dimensional character array</strong> is an array of one-dimensional character arrays.</li>
<li>This means that a two-dimensional character array consists of strings as its individual elements.</li>
<li>Like two-dimensional numeric arrays, two-dimensional character arrays must be declared before they are used in the program and should also be initialized.</li>
</ul>
<p><strong>String Handling Functions</strong></p>
<ul>
<li> C supports a number of string handling functions.</li>
<li>These functions are defined in the header file &lt;string.h&gt;.</li>
</ul>
<p><strong>strcmp()</strong> function &#8211; This function compares two strings character by character(ASCII comparison) and returns one of the three values {-1,0,1}.<br />
Syntax &#8211; strcmp(string1,string2);</p>
<p><strong>strcpy()</strong> function &#8211; This function is used to copy one string to the other.<br />
Syntax &#8211; strcpy(string1,string2);</p>
<p><strong>strcat()</strong> function &#8211; This function is used to concatenate two strings. That is, it appends one string at the end of the specified string.<br />
Syntax &#8211; strcat(string1,string2);</p>
<p><strong>strlen()</strong> function &#8211; This returns the number of characters in the string(i.e. string lenght). Here, the string length does not include the NULL character.<br />
Syntax &#8211; strlen(string);</p>
<p><strong>strncmp() </strong>function &#8211; This compares the first n characters of two input strings.<br />
Syntax &#8211; strncmp(string1,string2,n);</p>
<p><strong>strncpy()</strong> function &#8211; This copies first n characters of the second string to the first string.<br />
Syntax &#8211; strncpy(string1,string2,n);</p>
<p><strong>strncat()</strong> function &#8211; This appends first n characters of the second string at the end of the first string.<br />
Syntax &#8211; strncat(string1,string2,n);</p>
<p><strong>strlwr()</strong> function &#8211; This function is used to convert any uppercase letters present in a string to its equivalent lowercase.<br />
Syntax &#8211; strlwr(string);</p>
<p><strong>strupr()</strong> function &#8211; It converts any lowercase letters that appear in the input string to the uppercase.<br />
Syntax &#8211; strupr(string);</p>
<p><strong>Implementation of String Functions</strong></p>
<ul>
<li> <strong>String Concatenation</strong> &#8211; String concatenation is a process of appending one string to the end of another string.</li>
</ul>
<ol>
<li> Read two strings and call them as string1 and string2.</li>
<li>Traverse the first string to its end.</li>
<li>Attach the second string to the end of the first string.</li>
<li>Set the last character of the resultant string to a null character(\0).</li>
</ol>
<blockquote><p>char *stringcat (char str1[], char str2[])<br />
{<br />
int i, j, pos;<br />
for (i=0;str1[i]!= &#8216;\0&#8242;; i++)<br />
{<br />
;<br />
}<br />
pos=i;<br />
for (i=pos; str1[i]!= &#8216;\0&#8242;; i++)<br />
{<br />
str1[i] = str2[j++];<br />
}<br />
str1[i] = &#8216;\0&#8242;;<br />
return (str1);<br />
}</p></blockquote>
<ul>
<li><strong>String comparison</strong> &#8211; This is a process of comparing two strings to check whether they are equal or not.</li>
</ul>
<ol>
<li> Read two strings and call them as string1 and string2.</li>
<li>Find the length of each string.</li>
<li>Set the counter to zero.</li>
<li>Start comparing the first character of both strings and if they are equal then increment the counter and continue for the subsequent characters until the corresponding characters differ or till the end of the strings is reached.</li>
<li>Return zero, if they are equal; 1 if the string1 is greater than the second; and -1 the string1 is less than the string2.</li>
</ol>
<blockquote><p>int stringcomp (char str1[], char str2[], strlenght1, strlength2)<br />
{<br />
int i = 0, flag = 0;<br />
while ((i &lt; strlength1) &amp;&amp; (i &lt; strlength2))<br />
{<br />
if (str1[i] == str2[i])<br />
{<br />
i++;<br />
continue;<br />
}<br />
if (str1[i] &lt; str2[i])<br />
{<br />
flag = -1;<br />
break;<br />
}<br />
if (str1[i] &gt; str2[i])<br />
{<br />
flag = 1;<br />
break;<br />
}<br />
}<br />
return (flag);<br />
}</p></blockquote>
<ul>
<li><strong>String length</strong> &#8211; This is a process of finding the number of characters present in a given string.</li>
</ul>
<ol>
<li> Read a string.</li>
<li>Set the counter to zero.</li>
<li>Start traversing the string character-by-character and increment the counter everytime a new character is encountered.</li>
<li>Repeat step 3, until all the characters are traversed in the string.</li>
</ol>
<blockquote><p>nt stringlen (char string[])<br />
{<br />
int i, length = 0;<br />
for (i=0; string[i]!= &#8216;\0&#8242;;i++)<br />
{<br />
length = length + 1;<br />
}<br />
return (length);<br />
}</p></blockquote>
<p><a href="http://www.three2tango.com/techcorner/functions.html/">&lt;&lt;Previous Post</a></p>
<p style="text-align: right;"><a href="http://www.three2tango.com/techcorner/structures-and-unions.html/">Next Post&gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/stringscharacter-arays.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Functions</title>
		<link>http://www.three2tango.com/techcorner/functions.html/</link>
		<comments>http://www.three2tango.com/techcorner/functions.html/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 17:49:36 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2198</guid>
		<description><![CDATA[
The process of splitting the lengthy and comlex programs into a number of smaller units(called modules or sub-programs) is called modularization.
Programming in such an approach is called modular programming.
Modularization offers several advantages &#8211; Reusability, Debugging is easier, Build libraray.


Functions &#8211; A function is a set of instructions to carryout a particular task.
The function, after it&#8217;s executions, returns a single value.
Classified into standard functions and user-defined functions.


Function Definition &#8211; Defining a function means writing an actual code for the function which performs a specific and identifiable task.
Two ways &#8211; Non-ANSI style ...]]></description>
			<content:encoded><![CDATA[<ul>
<li>The process of splitting the lengthy and comlex programs into a number of smaller units(called modules or sub-programs) is called <strong>modularization</strong>.</li>
<li>Programming in such an approach is called <strong>modular programming</strong>.</li>
<li>Modularization offers several advantages &#8211; Reusability, Debugging is easier, Build libraray.</li>
</ul>
<ul>
<li><strong>Functions</strong> &#8211; A function is a set of instructions to carryout a particular task.</li>
<li>The function, after it&#8217;s executions, returns a single value.</li>
<li>Classified into standard functions and user-defined functions.</li>
</ul>
<ul>
<li><strong>Function Definition</strong> &#8211; Defining a function means writing an actual code for the function which performs a specific and identifiable task.</li>
<li>Two ways &#8211; Non-ANSI style and ANSI style.</li>
<li>Non-ANSI function definition -</li>
</ul>
<p>type name_of_function(parameter_list)<br />
parameter definition;<br />
{<br />
variable declaration;	/*within the function*/<br />
statement1;<br />
statement2;<br />
.<br />
.<br />
.<br />
return(value_computed);<br />
}</p>
<ul>
<li>ANSI style -</li>
</ul>
<p>type name_of_the_function(parameter definition)<br />
{<br />
variable declaration;	/*within the function*/<br />
statement1;<br />
statement2;<br />
.<br />
.<br />
.<br />
return(value_computed);<br />
}</p>
<ul>
<li>&#8216;<strong>return</strong>&#8216; &#8211; It is a means of communication from the called function to the calling function.</li>
<li>There may be one or more return statements.</li>
<li>When a return statement is encountered, the control is transferred to the calling function.</li>
</ul>
<ul>
<li>The point where the name of the function appears in any function is called <strong>function reference</strong>. This is also called as a <strong>function call</strong>.</li>
<li>When a function is called in any function or a program the execution of the calling function temporarily suspends and the control transfers to the called function. After the required computations are made in the function, the control returns to the calling function along with the computed value.</li>
</ul>
<ul>
<li><strong>Arguements and Parameters</strong> &#8211; are the variables used in a program and a function respectively.</li>
</ul>
<ul>
<li>Variables used in the function call are called <strong>arguements</strong>.</li>
<li>These are written within the parantheses followed by the name of the function.</li>
<li>They are also called actual parameters, as they are accepted in the main program(or a calling function).</li>
</ul>
<ul>
<li>Variables used in the function definition are called <strong>parameters</strong>.</li>
<li>They are also referred to as formal parameters, because they are not the accepted values.</li>
<li>They receive the values from the calling function. The parameters must be written within the parantheses followed by the name of the function in the function definition.</li>
</ul>
<ul>
<li>The number of arguements should be equal to the number of parameters.</li>
<li>There must be 1 to 1 mapping between arguements and parameters, i.e they should be in the same order and should have the same data type.</li>
<li>Same variables can be used as arguements and parameters.</li>
</ul>
<p><strong>Category of functions</strong> -</p>
<ul>
<li>arguements with return value</li>
<li>no arguements, no return value</li>
<li>arguements but no return value</li>
<li>no arguements but return value</li>
</ul>
<ul>
<li>An array name in C represents the address of the first element in that array. So, arrays are passed to functions as pointers.</li>
<li>We can pass either an entire array as an arguement or it&#8217;s individual elements.</li>
</ul>
<ul>
<li>Both the calling function and the called function are using their own variables. The existence of these variables is restricted to the calling function or to the called functions.This is known as scope of the variables.</li>
<li>Based on this scope, the variables can be classified into &#8211; local variables and global variables.</li>
<li>Variables whose existence is known to only to the main program or functions are called <strong>local variables</strong>.</li>
<li>Variables whose existence is known to both the main() function as well as other functions are called <strong>global variables</strong>.</li>
<li>Local variables are declared within the main program or a function. But the global variables are declared outside the main() and the other functions.</li>
</ul>
<ul>
<li><strong>Storage classes</strong> are used to define the scope(visibility) and the life-time of the variables and/or functions.</li>
<li>Four storage classes in C &#8211; auto, static, extern, register.</li>
</ul>
<ul>
<li><strong>static Variables</strong> &#8211; These variables hold their values throughout the execution of a program.</li>
<li>Two types &#8211; Internal static variables, External static variables.</li>
<li>Internal static variables are declared inside a function.</li>
<li>They are identical to <strong>auto</strong>matic variables in the function scope except that they retain their values throughout the program.</li>
<li>External static variables are declared outside of all functions including the mian() function.</li>
<li>They are global variables but are declared with the keyword <strong>static</strong>.</li>
<li>The external static variables cannot be used across multi-file program.</li>
<li>Static variables are initialised only once during the compile-time.</li>
<li>The initial values to be assigned must be always constants but not expressions.</li>
<li>If nothing is initialized to a static variable, by default, it is assigned a zero.</li>
</ul>
<ul>
<li><strong>register Variables</strong> &#8211; Variables whose values are stored in the CPU registers.</li>
<li>Since the values are stored in the CPU registers, they are accessed quickly and hence programs are executed faster.</li>
<li>Like automatic variables, the register variables are also local variables.</li>
<li>Declaring with the keyword register, it does not guarantee that they are actually register variables. It is valid only when the requested CPU register is available.</li>
</ul>
<ul>
<li><strong>Function declaration</strong> &#8211; means specifying the function as a variable depending on the return value.</li>
<li>Functions may be written before or after the main(). If the functions are written before the main() then function declaration is not required. But, the functions which are written after the main() function would require function declaration.</li>
<li>Two styles &#8211; Non-ANSI style and ANSI style.</li>
<li>Non-ANSI style &#8211; type_of_return_value name_of_function();</li>
<li>ANSI style &#8211; type_of_return_value name_of_function(dt1 p1,dt2 p2,&#8230;,dtn pn);</li>
</ul>
<ul>
<li>The process of transmitting the values from one function to other is known as <strong>parameter passing</strong>.</li>
<li>Two methods &#8211; call by value, call by reference.</li>
</ul>
<ul>
<li><strong>Call by value</strong> &#8211; When the values of the arguements are passed from a calling function to a called function, the values are copied into the called function.</li>
<li>If any changes are made to the values in the called function, there will not be any change in the original values within the calling function.</li>
</ul>
<ul>
<li><strong>Call by reference</strong> &#8211; In this method, the actual values are not passed, instead their addresses are passed to a calling function. Here, no values are copied as the memory locations themselves are referenced.</li>
<li>If any modification is made to the values in the called function, then the original values will get changed within the calling function.</li>
</ul>
<ul>
<li><strong>Recursion</strong> &#8211; is a technique that defines a function in terms of itself.</li>
<li>A function which calls itself.</li>
<li>Factorial calcualtion &#8211; coomon use of recursion.</li>
</ul>
<p><a href="http://www.three2tango.com/techcorner/arrays.html/">&lt;&lt;Previous Post</a></p>
<p style="text-align: right;"><a href="http://www.three2tango.com/techcorner/stringscharacter-arays.html/">Next Post&gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/functions.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arrays</title>
		<link>http://www.three2tango.com/techcorner/arrays.html/</link>
		<comments>http://www.three2tango.com/techcorner/arrays.html/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 18:10:53 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2105</guid>
		<description><![CDATA[
A programming language construct which stores and organizes a set of data items is called a data structure.
There are different types of data structures &#8211; arrays, stacks, queues, linked lists, structures, trees, files, etc.


An array can be defined as an ordered list of homogeneous data elements.
These elements may be of type int, float, char or double.
All these elemets are stored in consecutive memory locations.
An array is described by a single name or an identifier.
And each element in an array is referenced by a subscript(or an index) enclosed in a pair ...]]></description>
			<content:encoded><![CDATA[<ul>
<li>A programming language construct which stores and organizes a set of data items is called a <strong>data structure</strong>.</li>
<li>There are different types of data structures &#8211; arrays, stacks, queues, linked lists, structures, trees, files, etc.</li>
</ul>
<ul>
<li>An <strong>array</strong> can be defined as an ordered list of homogeneous data elements.</li>
<li>These elements may be of type int, float, char or double.</li>
<li>All these elemets are stored in consecutive memory locations.</li>
<li>An array is described by a single name or an identifier.</li>
<li>And each element in an array is referenced by a subscript(or an index) enclosed in a pair of square brackets.</li>
<li>The subscript indicates the position of an individual data item in an array.</li>
<li>The subscipt must be an unsigned positive integer.</li>
<li>Because of these subscripts, sometimes an array is called as a subscripted variable.</li>
</ul>
<ul>
<li> Arrays classified into &#8211; one-dimensional array and multi-dimensional arrays.</li>
<li>The dimensionality of an array is determined by the number of subscripts present in the given array.</li>
<li>An array must be declared before it appears in a C program. At the same time, the size of an array must be specified.</li>
</ul>
<ul>
<li><strong>One-dimensional array</strong> &#8211; This is a linear list of a fixed number of data items of the same type.</li>
<li>Similar to a row or a coloumn matrix.</li>
<li>Also called a single-dimensional array or a one-subscripted variable.</li>
<li>Syntax &#8211; data-type arrayname[size];</li>
</ul>
<ul>
<li><strong>Subscript</strong> must be an unsigned positive integer constatnt or an expression.</li>
<li>Subscript of subscript is not allowed.</li>
<li>C does not perform bounds checking for an array.</li>
<li>In C, the subscript value ranges from 0 to one less than the maximum size.</li>
</ul>
<ul>
<li>The total amount of memory that can be allocated to a one-dimensional array is computed as -</li>
</ul>
<p>Total size = size * [sizeof(data_type)];</p>
<ul>
<li>Initialization of a one-dimensional aray</li>
</ul>
<p>Syntax &#8211; data_type array_name[size] = {element1,element2,&#8230;,elementn};</p>
<ul>
<li><strong>Multi-dimensional arrays</strong> &#8211; If the number of subscripts is more than one then such arrays are called multi-dimensional arrays.</li>
<li>Two-dimensional(2-D) array, three-dimensional(3-D) array, and so on.</li>
</ul>
<ul>
<li><strong>Two-dimensional array</strong> &#8211; It is an ordered table of homogeneous elements.</li>
<li>Generally referred to a matrix of some rows and some coloumns.</li>
<li>Also called a two-subscripted variable.</li>
<li>Syntax &#8211; data_type array_name[rows][coloumns];</li>
<li>Row-major order and Coloumn-major order.</li>
</ul>
<ul>
<li>Initialization of a two-dimensional array</li>
</ul>
<p>Syntax &#8211; data_type array_name[size1][size2]={e1,e2,&#8230;,en};</p>
<p><a href="http://www.three2tango.com/techcorner/loop-control-structuresdecision-making-looping.html/">&lt;&lt;Previous Post</a></p>
<p style="text-align: right;"><a href="http://www.three2tango.com/techcorner/functions.html/">Next Post&gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/arrays.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loop Control Structures(Decision Making &amp; Looping)</title>
		<link>http://www.three2tango.com/techcorner/loop-control-structuresdecision-making-looping.html/</link>
		<comments>http://www.three2tango.com/techcorner/loop-control-structuresdecision-making-looping.html/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 17:43:54 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2094</guid>
		<description><![CDATA[
Looping is a powerful programing technique through which a group of statements is executed repeatedly, until certain specified condition is satisfied.
Looping is also called a repetitive or an iterative control mechanism.
A loop in a program essentially consists of two parts, one is called the body of the loop and other is known as the control statement.
The control statement performs a logical test whose result is either true or false. If the result of this logical test is true, then the statements contained in the body of the loop are executed. ...]]></description>
			<content:encoded><![CDATA[<ul>
<li><strong>Looping</strong> is a powerful programing technique through which a group of statements is executed repeatedly, until certain specified condition is satisfied.</li>
<li>Looping is also called a repetitive or an iterative control mechanism.</li>
<li>A loop in a program essentially consists of two parts, one is called the body of the loop and other is known as the control statement.</li>
<li>The control statement performs a logical test whose result is either true or false. If the result of this logical test is true, then the statements contained in the body of the loop are executed. Otherwise, the loop is terminated.</li>
<li>The control statement can be placed either before or after the body of the loop.</li>
<li>If the control statement is placed before the body of the loop, it is called entry-controlled loop.</li>
<li>If the control statement is written after the body of the loop, it is called the exit-controlled loop.</li>
<li>If the logical test condition is carelessly designed, then there may be a possibility of formation of an infinite loop which keeps executing the statements over and over again.</li>
</ul>
<ul>
<li><strong>while-statement</strong> &#8211; This is used to execute a set of statements repeatedly as long as the specified condition is true.</li>
<li>Referred to as pretest loop.</li>
<li>Syntax -</li>
</ul>
<p>while (logexp)<br />
{<br />
statement;<br />
}</p>
<ul>
<li><strong>do-while statement</strong> &#8211; This is used to execute a set of statements repeatedly until the logical test results in false.</li>
<li>this is called the post-test loop. Because the test for repetition is made at the end of each pass.</li>
<li>Syntax -</li>
</ul>
<p>do<br />
{<br />
statement;<br />
}<br />
while (logexp);</p>
<ul>
<li>At least once, the body of do-while is executed.</li>
<li>The body of do-while must contain either implicitely or explicitely statements to modify the variable involved in the logexp.</li>
</ul>
<ul>
<li><strong>for-statement</strong> &#8211; This statement is used when the programmer knows how many times a set of statements is executed.</li>
<li>Syntax -</li>
</ul>
<p>for (expression1;expression2;expression3)<br />
{<br />
statement;<br />
}</p>
<ul>
<li><strong>Nested-for statement</strong> &#8211; If there are many data items to be processed against a set of elements repeatedly, then a single for statement is not adequate. Then, we must use the nested-for loop.</li>
<li>If one for statement is completely placed within the other, it is known as the nested-for statement.</li>
<li>Syntax -</li>
</ul>
<p>for(exp11;exp12;exp13)<br />
{<br />
for(exp21;exp22;exp23)<br />
{<br />
statement1;<br />
statement2;<br />
}<br />
}</p>
<p><strong>Jumps in loops</strong> -</p>
<ol>
<li>break statement &#8211; This is used to teminate a loop and exit from a particular switch case label.</li>
<li>continue statement &#8211; This is used as the bypasser. The control does not come out of the loop, instead it skips the remaining statements within the body of that loop and transfers to the beginning of the loop.</li>
</ol>
<p><a href="http://www.three2tango.com/techcorner/control-statementsdecision-making-branching.html/">&lt;&lt;Previous Post</a></p>
<p style="text-align: right;"><a href="http://www.three2tango.com/techcorner/arrays.html/">Next Post&gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/loop-control-structuresdecision-making-looping.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Control Statements(Decision Making &amp; Branching)</title>
		<link>http://www.three2tango.com/techcorner/control-statementsdecision-making-branching.html/</link>
		<comments>http://www.three2tango.com/techcorner/control-statementsdecision-making-branching.html/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 16:36:05 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2080</guid>
		<description><![CDATA[
Normally, the statements in a program are executed in the order in which they appear in the program. This type of execution is called sequential execution.


Control structures &#8211; define the order of execution of statements.


Conditional control statements &#8211; involves both decision making and branching.


if-statement.
if-else statement.
Nested-if-statement.
switch statement.


if-statement &#8211; used to execute a statement or a set of statements conditionally.
Also called a one-way branching.
Syntax -

if (condition)
{
statement;
}

if-else statement &#8211; The if statement is used to execute only one action. If there are two statements to be executed alternatively, then if-else statement is used.
Two-way ...]]></description>
			<content:encoded><![CDATA[<ul>
<li>Normally, the statements in a program are executed in the order in which they appear in the program. This type of execution is called sequential execution.</li>
</ul>
<ul>
<li>Control structures &#8211; define the order of execution of statements.</li>
</ul>
<ul>
<li>Conditional control statements &#8211; involves both decision making and branching.</li>
</ul>
<ol>
<li>if-statement.</li>
<li>if-else statement.</li>
<li>Nested-if-statement.</li>
<li>switch statement.</li>
</ol>
<ul>
<li>if-statement &#8211; used to execute a statement or a set of statements conditionally.</li>
<li>Also called a one-way branching.</li>
<li>Syntax -</li>
</ul>
<blockquote><p>if (condition)<br />
{<br />
statement;<br />
}</p></blockquote>
<ul>
<li>if-else statement &#8211; The if statement is used to execute only one action. If there are two statements to be executed alternatively, then if-else statement is used.</li>
<li>Two-way branching.</li>
<li>Syntax -</li>
</ul>
<blockquote><p>if (condition)<br />
{<br />
statement1;<br />
}<br />
else<br />
{<br />
statement2;<br />
}</p></blockquote>
<ul>
<li>Nested-if statement &#8211; If there are more than two alternatives to select, then the nested-if statements are used.</li>
<li>Enclosing an if statement within another if statement is called the nested-if statement.</li>
<li>Syntax -</li>
</ul>
<blockquote><p>if (condition1)<br />
{<br />
if (condition2)<br />
{<br />
statement1;<br />
}<br />
else<br />
{<br />
statement2;<br />
}<br />
}<br />
else if (condition3)<br />
{<br />
statement3;<br />
}<br />
else<br />
{<br />
statement4;<br />
}</p></blockquote>
<ul>
<li>There are many ways to nest one if-else within the other.</li>
</ul>
<ul>
<li>switch statement &#8211; The switch statement provides a multiple way of branching.</li>
<li>It allows the user to select any one of the several alternatives, depending on the value of an expression.</li>
<li>Syntax -</li>
</ul>
<blockquote><p>switch (expression)<br />
{<br />
case label1 : block1;<br />
break;<br />
case label2 : block2;<br />
break;<br />
.<br />
.<br />
.<br />
case labelmax : blockmax;<br />
break;<br />
case default : dblock;<br />
break;<br />
}</p></blockquote>
<ul>
<li>The expression is of type int or char.</li>
<li>Depending on the value of an expression, execution branches to a particular case label and then all the statements belonging to that case label are executed.</li>
<li>The break statement indicates the end of a particular case label and thereby the switch statement is terminated.</li>
<li>The case default is executed, when the value of an expression is not matched with any of the case labels.</li>
<li>The semicolons should not be placed at the end of switch (expression).</li>
</ul>
<ul>
<li>goto-statement &#8211; an unconditional control statement.</li>
<li>To transfer the control from one point to another in a C program.</li>
<li>Syntax -<br />
<blockquote><p>goto label;</p></blockquote>
</li>
<li>Forward jump and backward jump.</li>
<li>Bachward jump will form a loop.</li>
<li>The use of goto statement in a structured programming language like C should be avoided. Use if and only if it is unavoidable.</li>
<li>The goto statement may create an infinite loop where the computer enters a permanent loop. The careful and cautious design would resolve such situations.</li>
<li>A program may contain any number of goto statements.</li>
<li>No two statements can have the same label.</li>
</ul>
<p><a href="http://www.three2tango.com/techcorner/operators-expressions.html/">&lt;&lt;Previous Post</a></p>
<p style="text-align: right;"><a href="http://www.three2tango.com/techcorner/loop-control-structuresdecision-making-looping.html/">Next Post&gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/control-statementsdecision-making-branching.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Operators &amp; Expressions</title>
		<link>http://www.three2tango.com/techcorner/operators-expressions.html/</link>
		<comments>http://www.three2tango.com/techcorner/operators-expressions.html/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 18:28:31 +0000</pubDate>
		<dc:creator>Dileep</dc:creator>
				<category><![CDATA[C and C++]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[corporate readiness program at wipro]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[Object-oriented]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Readiness Program]]></category>
		<category><![CDATA[wipro talent transformation]]></category>
		<category><![CDATA[Wipro Technologies Training]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2031</guid>
		<description><![CDATA[
Operators are used to carryout the arithmetic and logical operations.
Operators act as connectors.
The values that can be operated by these operators are called operands.
C operators &#8211; unary operators, binary operators, ternary operators.


An operator that acts upon only one operand is known as a unary operator.
Egs &#8211; unary minus, logical NOT, bitwise complementation.


Binary operators act upon two operands.
Classified into four &#8211; arithmetic operators, logical operators, relational operators, bitwise operators.


Arithmetic operators are used to perform basic arithmetic operations such as addition, subtraction, multiplication and division.
An expression involving arithmetic operators is called an arithmetic ...]]></description>
			<content:encoded><![CDATA[<ul>
<li>Operators are used to carryout the arithmetic and logical operations.</li>
<li>Operators act as connectors.</li>
<li>The values that can be operated by these operators are called operands.</li>
<li>C operators &#8211; unary operators, binary operators, ternary operators.</li>
</ul>
<ul>
<li>An operator that acts upon only one operand is known as a unary operator.</li>
<li>Egs &#8211; unary minus, logical NOT, bitwise complementation.</li>
</ul>
<ul>
<li>Binary operators act upon two operands.</li>
<li>Classified into four &#8211; arithmetic operators, logical operators, relational operators, bitwise operators.</li>
</ul>
<ul>
<li>Arithmetic operators are used to perform basic arithmetic operations such as addition, subtraction, multiplication and division.</li>
<li>An expression involving arithmetic operators is called an arithmetic expression.</li>
</ul>
<ul>
<li>Increment operator &#8211; used to increment the value of an integer quantity by one.</li>
<li>Represented by &#8216;++&#8217;.</li>
<li>Decrement operator &#8211; used to reduce the value of an integer by one.</li>
<li>Represented by &#8216;- -&#8217;.</li>
</ul>
<p><strong>Program 1</strong></p>
<blockquote><p>/*Program to illustrate the basic arithmetic operations*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
int n1,n2;	/*variable declaration*/<br />
int sum,diff,prod,quotient,remainder;<br />
n1=5;<br />
n2=3;<br />
sum=n1+n2;<br />
diff=n1-n2;<br />
prod=n1*n2;<br />
quotient=n1/n2;<br />
remainder=n1%n2;<br />
printf(&#8220;SUM = %d\n&#8221;,sum);<br />
printf(&#8220;DIFFERENCE = %d\n&#8221;,diff);<br />
printf(&#8220;PRODUCT = %d\n&#8221;,prod);<br />
printf(&#8220;QUOTIENT = %d\n&#8221;,quotient);<br />
printf(&#8220;REMAINDER = %d\n&#8221;,remainder);<br />
}</p></blockquote>
<p><strong>Program 2</strong></p>
<blockquote><p>/*Program to illustrate the use of an increment operator*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
int a=3,b=6;<br />
printf(&#8220;a = %d\n&#8221;,a++);<br />
printf(&#8220;b = %d\n&#8221;,++b);<br />
}</p></blockquote>
<p><strong>Program 3</strong></p>
<blockquote><p>/*Program to illustrate the use of a decrement operator*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
int m=6,n=8;<br />
printf(&#8220;m = %d\n&#8221;,- -m);<br />
printf(&#8220;n = %d\n&#8221;,n- -);<br />
}</p></blockquote>
<ul>
<li>Relational operators &#8211; used to compare two operands given in an expression.</li>
<li>Result in either a TRUE(non-zero,1) or a FALSE(0) value.</li>
<li>Six relational operators &#8211; &lt;, &lt;=, &gt;, &gt;=, ==, !=.</li>
<li>A relational expression can be defined as a meaningful combination of operands and relational operators.</li>
</ul>
<p><strong>Program 4</strong></p>
<blockquote><p>/*Program to check whether given two integers are equal*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
int x=2,y=2;<br />
if (x= =y)<br />
printf(&#8220;x and y are equal\n&#8221;);<br />
}</p></blockquote>
<p><strong>Program 5</strong></p>
<blockquote><p>/*Program to compare two values*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
float m=2.333, n=0.0232;<br />
if (m&gt;n)<br />
printf(&#8220;m is greater than n\n&#8221;);<br />
}</p></blockquote>
<ul>
<li>Logical operators &#8211; This class of C operators is used to make decisions.</li>
<li>AND, OR, NOT.</li>
<li>The result of these operators is either TRUE or FALSE.</li>
<li>The logical operators are used to connect one or more relational expressions.</li>
<li>Expresions involving the logical operators are called the logical expressions.</li>
</ul>
<p><strong>Program 6</strong></p>
<blockquote><p>/*Program to illustrate the logical ANDing and ORing operations*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
int a,b,c;<br />
a = 4;<br />
b = 3;<br />
c = a &amp;&amp; b;<br />
b = a || b || c;<br />
a = a &amp;&amp; b || c;<br />
printf(&#8220;%d,%d,%d&#8221;,a,b,c);<br />
}</p></blockquote>
<ul>
<li>Bitwise operators &#8211; To perform the bitwise operations, C provides six bitwise operators.</li>
</ul>
<ol>
<li>&amp;  &#8211; Bitwise AND</li>
<li>|  &#8211; Bitwise OR</li>
<li>^  &#8211; Exclusive-OR(XOR)</li>
<li>~  &#8211; 1&#8242;s complement</li>
<li>&lt;&lt; &#8211; Left shifting of bits</li>
<li>&gt;&gt; &#8211; Right shifting of bits</li>
</ol>
<p><strong>Program 7</strong></p>
<blockquote><p>/*Program to illustrate the bitwise operators*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
unsigned int x,y;<br />
x=128;<br />
y=32;<br />
x=x&gt;&gt;1;<br />
printf(&#8220;After right-shifting by 1, x = %d\n&#8221;,x);<br />
y=y&lt;&lt;2;<br />
printf(&#8220;After left-shifting by 2, y = %d\n&#8221;,y);<br />
}</p></blockquote>
<ul>
<li>Conditional operator &#8211; This is used to test the relationship between two variables.</li>
<li>It is used in conjunction with a relational expression.</li>
<li>Syntax &#8211; &lt;expression&gt;?&lt;value1&gt;:&lt;value2&gt;;</li>
</ul>
<p><strong>Program 8</strong></p>
<blockquote><p>/*Program to illustrate the conditional operator*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
int a=4,b=5,result1,result2;<br />
result1=a&gt;b?a:b;<br />
printf(&#8220;The result1 = %d\n&#8221;,result1);<br />
result2=a&lt;b?a:b;<br />
printf(&#8220;The result2 = %d\n&#8221;,result2);<br />
}</p></blockquote>
<p><strong>Special operators of C</strong></p>
<ul>
<li>Comma operator</li>
<li>sizeof() operator</li>
<li>Address operator</li>
<li>Dereferencing operator</li>
<li>Dot operator</li>
<li>Arrow operator</li>
</ul>
<p><strong>Program 9</strong></p>
<blockquote><p>/*Program to illustrate the use of the comma operator in inter-changing the values of two variables*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
int a,b,temp;<br />
b=(a=20,a+10);<br />
printf(&#8220;a = %d and b = %d(before)\n&#8221;,a,b);<br />
temp=a,a=b,b=temp;<br />
printf(&#8220;a = %d and b = %d(after)\n&#8221;,a,b);<br />
}</p></blockquote>
<ul>
<li>The sizeof() operator returns the size(i.e, number of bytes) of an operand.</li>
<li>It is a function and therefore has to be written in lowercase letters.</li>
</ul>
<p><strong>Program 10</strong></p>
<blockquote><p>/*Program to illustrate the use of sizeof() operator*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
int x;<br />
float y;<br />
char ch=&#8217;y';<br />
x=10;<br />
y=1000;<br />
printf(&#8220;size of x = %d\n&#8221;, sizeof(x));<br />
printf(&#8220;size of y = %d\n&#8221;, sizeof(y));<br />
printf(&#8220;size of ch = %d\n&#8221;, sizeof(ch));<br />
printf(&#8220;size of double = %d\n&#8221;, sizeof(double));<br />
}</p></blockquote>
<p>Precedence, Associativity of all C operators &#8211; Table</p>
<table border="1">
<tbody>
<tr style="height: 8.85pt;">
<td><strong>Operator Category</strong></td>
<td><strong>Operators</strong></td>
<td><strong>Precedence</strong></td>
<td><strong>Associativity</strong></td>
</tr>
<tr>
<td>Parentheses,braces</td>
<td>( ),[ ]</td>
<td>1</td>
<td>L to R</td>
</tr>
<tr>
<td>Unary Operators</td>
<td>-, ++, &#8211; -, !, ~, &amp;</td>
<td>2</td>
<td>R to L</td>
</tr>
<tr>
<td>Multiplicative Operators</td>
<td>*, /, %</td>
<td>3</td>
<td>L to R</td>
</tr>
<tr>
<td>Additive Operators</td>
<td>+, -</td>
<td>4</td>
<td>L to R</td>
</tr>
<tr>
<td>Shift Operators</td>
<td>&lt;&lt;,&gt;&gt;</td>
<td>5</td>
<td>L to R</td>
</tr>
<tr>
<td>Relational Operators</td>
<td>&lt;,&lt;=,&gt;,&gt;=</td>
<td>6</td>
<td>L to R</td>
</tr>
<tr>
<td>Equality Operators</td>
<td>==, !=</td>
<td>7</td>
<td>L to R</td>
</tr>
<tr>
<td>Bitwise Operators</td>
<td>&amp;,^,|</td>
<td>8</td>
<td>L to R</td>
</tr>
<tr>
<td>Logical Operators</td>
<td>&amp;&amp;,||</td>
<td>9</td>
<td>L to R</td>
</tr>
<tr>
<td>Conditional Operators</td>
<td>?,:</td>
<td>10</td>
<td>R to L</td>
</tr>
<tr>
<td>Assignment Operators</td>
<td>=,+=,-=,*=,/=,%=,&amp;=,^=,|=,&lt;&lt;=,&gt;&gt;=</td>
<td>11</td>
<td>R to L</td>
</tr>
<tr>
<td>Comma operator</td>
<td>,</td>
<td>12</td>
<td>L to R</td>
</tr>
</tbody>
</table>
<ul>
<li>Shorthand assignment operators &#8211; a compact way of writing assignment statements in an expression.</li>
</ul>
<p><strong>Program 11</strong></p>
<blockquote><p>/*Program to illustrate the comapct representation of arithmetic operators*/<br />
#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
int x=3,y=4,z=1;<br />
x+=y;<br />
y-=x;<br />
z*=x;<br />
printf(&#8220;%d\n&#8221;,x);<br />
printf(&#8220;%d\n&#8221;,y);<br />
printf(&#8220;%d\n&#8221;,z);<br />
}</p></blockquote>
<ul>
<li>In some applications, we may often want to change the data type of the variables. This process is known as data type conversion.</li>
<li>Also called type casting.</li>
<li>Syntax &#8211; (data type)variable</li>
</ul>
<ul>
<li>Preporcessor directives &#8211; C preprocessor is a collection of special statements called the preprocessor directives.</li>
<li>The preprocessor directives are executed before the C program is compiled.</li>
<li>Usually written at the beginning of the pogram. However, it is not mandatory.</li>
<li>There is no semicolon at the end of the preprocessor directives.</li>
</ul>
<p><strong>Program 12</strong></p>
<blockquote><p>/*Program to illustrate the use of sqrt(),sin(),cos() and tan()*/<br />
#include&lt;stdio.h&gt;<br />
#include&lt;math.h&gt;<br />
void main()<br />
{<br />
float x,y,sq,sinx,cosx,tanx;<br />
x=4.0;<br />
y=30.0;<br />
sq=sqrt(x);<br />
y=30*(3.142/180.0);	/*convert to radians*/<br />
sinx=sin(y);<br />
cosx=cos(y);<br />
tanx=tan(y);<br />
printf(&#8220;Square root of x = %f\n&#8221;,sq);<br />
printf(&#8220;Sine value of y = %f\n&#8221;,sinx);<br />
printf(&#8220;Cosine value of y = %f\n&#8221;,cosx);<br />
printf(&#8220;Tangent value of y = %f\n&#8221;,tanx);<br />
}</p></blockquote>
<p><strong>Program 13</strong></p>
<blockquote><p>/*Program to illustrate the use of abs(),log10(),pow() &amp; exp()*/<br />
#include&lt;stdio.h&gt;<br />
#include&lt;math.h&gt;<br />
void main()<br />
{<br />
float x,y,xpy,lg,xp;<br />
int z,az;<br />
x=2.0;<br />
y=3.0;<br />
z=-4;<br />
az=abs(z);<br />
lg=log10(x);<br />
xp=exp(y);<br />
xpy=pow(x,y);<br />
printf(&#8220;Absolute value of z = %d\n&#8221;,az);<br />
printf(&#8220;Logarithm of x = %d\n&#8221;,lg);<br />
printf(&#8220;e to the power y = %f\n&#8221;,xp);<br />
printf(&#8220;x to the power y = %f\n&#8221;,xpy);<br />
}</p></blockquote>
<p><a href="http://www.three2tango.com/techcorner/managing-input-and-output-operations.html/">&lt;&lt;Previous Post</a></p>
<p style="text-align: right;"><a href="http://www.three2tango.com/techcorner/control-statementsdecision-making-branching.html/">Next Post&gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/operators-expressions.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

