Sunday 6 April 2014

Explain boolean logic.


Boolean logic-They are used to store result of a comparison.It can hold only two values true or false.
Comparison operators-These are used on numeric values,string and boolean values.
Here var1 is bool type,var2 and var3 may vary
        operator      category     example         result
  • = =      binary         var1=var2==var3           var1 value is true if var2 is equal to var3 otherwise value is false
  • !=        binary         var1=var2!=var3            var1 value is true if var2 is not equal to var3 otherwise value is false
  • <        binary           var1=var2<var3            var1 value is true if var2 is less than var3 otherwise value is false
  • >        binary           var1=var2>var3            var1 value is true if var2 is greater than var3 otherwise value is false
  • <=        binary         var1=var2<=var3        var1 value is true if var2 is less than equal to var3 otherwise value is false
  • >=        binary        var1=var2>=var3          var1 value is true if var2 is greater than equal to var3 otherwise value is false       
Examples
comparison operator use on numeric values
  • bool var1;
var1=var2<10;
here if var2 is less than 10 then var1 value is true else false.
comparison operator use on string
  • bool var1;
var1=var2=="lechu";
if var2 value is lechu then var1 value is true else false.
comparison operator use on boolean values
  • bool var1;
var1=var2==true;
if var2 value is true then var1 value is true else false
Note-common error-if var1<var2 it doesn't mean that var2>var1 it may be var1=var2.So don't assume the result.

Boolean operators-These are used on boolean values.

operator    category    example            result
  • !        unary        var1=!var3        var1 value is true if var2 is false otherwise value is false
  • &        binary         var1=var2&var3        var1 value is true if var2,var3 both are true otherwise value is false
  • |        binary        var1=var2|var3        var1 value is true if var2,var3 both or either one is true otherwise value is false
  • ^        binary        var1=var2^var3        var1 value is true if var2 or var3 is true not both otherwise value is false
Example
Boolean operator on boolean values
  • bool var1;
var1=var2&true
here var1 is true if var2 is also true else var1 is false.
conditional boolean operators-This operate same as &,! but difference is,the value of first operand is false there is no need to consider value of second operator.Difference in the way result obtained gives better performance.
operator    category    example            result
  • &&        binary         var1=var2&&var3        var1 value is true if var2,var3 both are true otherwise value is false
  • ||        binary        var1=var2||var3        var1 value is true if var2,var3 both or either one is true otherwise value is false
Example
var1=(var2!=0)&&(var3/var2>2);

Explain flow control and its 2 types branching and looping.

Flow control-There are two methods of controlling program flow ie, controlling order of execution of lines in C# code.They are branching and looping.These methods use boolean logic.
Branching-Here code is executed when the condition given is true.For example-only execute code if my val is less than 10.Result is shown by true or false.
Looping-Here same statement will be executed repeatedly for a certain amount of times,until a test condition is reached.Its type is bool.

Monday 10 March 2014

How to create a window application.Features on VS in this app.

Create a windows application by selecting File->new ->Project then project type Visual C# itself as console application Then in templates select windows application instead of console application.Create in same location as console application  ie.. (C:\BegVCSharp\Chapter2). with default name consoleapplication1.After clicking ok you can view an empty window form.Move mouse pointer on toolbar on left side of screen,double click on button option to add button to form.
Double click on button added to window form to display C# code.Modify it to -

private void button1_Click(object sender,EventArgs e)
{

MessageBox.Show("The first window app");
}

Run the application.
Click button when running to see message dialog box.
Exit clicking x.   
Features of VS
Here when double clicked on button on toolbar,VS knew that you wanted to write code to execute on click on button by user.
Also without code we can resize,minimize  and move around windows form and button.
UI ie, user interface building blocks are on toolbar to perform different functions like button option.
A properties window to make changes like for button option text changed to click me or which is currently set to button1.Other changes can be made are color changing,size changing etc..

Friday 7 March 2014

How to create a console application.Explain solution explorer,Properties window,Error list window functions.

Console applications
Create a new console application project by selecting File->New->Project or by pressing key shortcut or by clicking on corresponding icon in the toolbar.
Select visual C# in project types,console applications in templates,change location and other settings as they are.
Click on button.
Once project is initialized add following lines of code to the file displayed in main window.

namespace ConsoleApplication1
{
    class Program
    {
        static void main(string[] args)
        {
        Console.WriteLine("The first app beggining in c# programming!");
        Console.ReadKey();
        }
        }
}
Select debugg->start menu item or press a keyboard shortcut or a toolbar icon.You will see result in few minutes.
The first app beggining in c# programming!
Press a key to exit the application .
The console application will terminate as soon as they finish execution,ie, you don't get a chance to see result.To get around here code is told to wait for a key press before terminating.You will see this technique  used in many examples.

Solution explorer
This shows files in ConsoleApplication1.project created here.The code added file here is program.cs,It is shown along with another code file assemblyInfo.cs and a resource.cs file.
Remember all C# files have a .cs file extension .
Function done here is renaming file,deleting them from your project.Other types file are resource files such as bitmap images and sound files not c# codes here.
Reference entry contains list of .net libraries used in your project.

Properties window
It shows additional information about whatever you select in the window above.Changes made in this window will affect the code directly.

Error list window
It displays error when error exist in the code.Like missing of semicolon etc..The error shown is double clickedthen cursor will jump to the error in source code.Here you can fix it quickly.Also can see red wavy lines at position of errors in code.Error is shown by line number.If line numbers are not displayed in VS editor ,turn it on through Tools->options menu item ->Text Editor->General here tick auto list members

Wednesday 5 March 2014

What is asp.net?

It is part of the .net  framework.
Active Server Pages(ASP.NET)
It is a programming framework used to create web applications where web pages can be viewed by any browser.It is dynamically generating web content by .net framework.This section of .net framework called as asp.net(ie,Active Server Pages.NET).

Compare C++ and C#.What is C#.Explain variables and expressions in C#.Role of namespace in C#.

compare C# and C++-It is an evolution of C and C++ languages and has been created by Microsoft specially to work with .net platform.C# is able to make use of every feature that .net

framework code library has to offer compared to visual basic.Developing applications using C# is simpler than C++ because the syntax is simpler.Need to write more

codes in C# to carry same task than in C++,but will get benefit that code is more robust and debugging is simpler.

What is C#?
It is an evolution of C and C++ languages and has been created by Microsoft specially to work with .net platform.C# is able to make use of every feature that .net
framework code library has to offer compared to visual basic.Developing applications using C# is simpler than C++ because the syntax is simpler.Need to write more
codes in C# to carry same task than in C++,but will get benefit that code is more robust and debugging is simpler.C# is madeup of a series of statements,each of which is terminated with a semicolon.C# is block structured language ,meaning that all statements are part of a block of code.These blocks are delimited with braces({ and}) may contain any number of statements or none at all.
A simple block of C#
{
stmt;
}

Blocks may contain other blocks.
{
stmt;
    {
    stmt;
    }
stmt;
}
Comments when added allows you to add descriptive text to your code.Comments can be given in 4 ways in C3.Marker given at beginning and end of a comment or give marker then everything on rest of line is a comment.You can use single line comments with two or three symbols at start.

/*This is a comment*/
//This is a comment
///This a a comment

C# is case sensitive.
Console.WriteLine("The first app in C #");
This is the correct code
VS suggest you commands that you might use when you try to enter code.
Any keyword that starts with a # is a preproccessor directive.
All C# code has a cs.file extension.

Variables and expressions in C#

If computer programs are performing operations on data.Then this implies that you need some way of storing that data and some method to manipulate it.These two functions are performed by variables and expressions.

Variables in C#

variable naming rules
You cannot choose any set of characters as variable name.The first character must be either a letter,underscore(_) or at the rate aymbol(@),seqeuent characters may be letters,underscore or numbers.Since C# is case-sensitive you can have multiple variables whose names differ only in case.
example
myvariable
Myvariable
myVariable

Naming convention
Naming conventions in .net framework is of 2 types-PascalCase and camelCase.Thet both specify that each word in a name should be in lowecase ,except for its first letter.In camelcase casing addition rule is that first word should start with a lowercase.
camelCase variable names-
age
firstName
timeOfDeath
PascalCase variable names-
Age
LastName
WinterOfDiscontent

Declaration and initialization of variable
Variable is declared using type and variable name.
example
int age;
Multiple variables can be declared at same time by seperating it with commas.
example
int age,weight;
Variables must be intitalized before using them
example
int age=15;
It is initialization of variable age with 15
Variables can be initialized and declared at same time.
int age=15;
Also initialization,declaration,multiple variables at same time
int age=15;weight=40;

Use of variable
It store data in memory ie,consider variable has box,memory as shelf,data as thing stored in box of shelf.As things can be looked at or taken out same way data can be looked at or taken out from variable.As boxes can be different shape for holding different things same way variable can be in different types for holding different data.Firstly declare variable before using it as storage units ie,assiging a name and type,otherwise compiler show it as error.
Number is stored in memory as series of zero and one.ie,a variable with 2 bits can store only 4 numbers -
0= 00
1= 01
2= 10
3= 11
A variable with 3 bit can store 7 numbers only.

Types of variable
Listing types of variable as in .net framework library
Type     Alias for
sbyte     System.SByte
byte    System.Byte
short    System.Int16
ushort    System.UInt16
int    System.Int32
uint    System.UInt32
long    System.Int64
ulong    System.UInt64
float    System.Single
double    System.Double
decimal    System.Decimal
char    System.Char
bool    System.Boolean
string    System.String

Write a console application in C# showing declaration of two variables,assigning them values and then outputing these values.
static void main(string args)
{
int myinteger;
int mystring;
myinteger=17;
mystring="    \"myinteger\"  is ";
Console.WriteLine("{0},{1}",mystring,myinteger);
Console.ReadKey();
}
Execute the code
Output
"myinteger" is 17
Description of code-The code declaring two variables -
int myinteger;
string mystring;
Here variable name is myinteger with type int.And variable name is mystring with type string.
The code assigning values-
myinteger=17;
mystring="    \"myinteger\"  is";
There are certain problems like using double quotation mark inside the string ie,"integer" into string-  " \"myinteger\" is".
Here a sequence \" is used to escape a double quotation mark.Otherwise comipler error is shown.Escape sequence are of different types.

Escape sequences used in string literal
escape sequence         character produced
\'               single quotation mark
\''            double quotation mark
\\            backslash
\0            null
\a            alert(cause a beep)
\b             backspace
\f            float
\n            form feed
\n             new line
\r            carriage return
\t            horizontal tab
\v            vertical tab


string verbatim
It is used to show all characters inside double quotation mark is included in th string including end of line character and characters that would otherwise need escaping.
example
@"verbatim string literal."
Here fixed values are assigned to variables myinteger and mystring  using assignment operator =.
Console.WriteLine("{0}{1}",mystring,myinteger);
Here within brackets you have a string and a list of variables.Each set of curly brackets in string is a placeholder that will contain contents of one of variables in list.Each placeholder is represented as an integer enclosed in curly brackets.The integers start at 0 and increment by 1,total number of placeholder should match number of variables specified.In ouput placeholder is replaced by value of variable.
Console.ReadKey();
It pauses code execution until you press a key.

Expression
To manipulate variables we use expressions.Operands when used with operators create an expression.
Operators
It can be classified into
*)unary operator-Which act on single operand.
*)binary operator-Which act on two operands.
*)trenary operator-Which act on three operands.
Operator used with numeric types(integer and floating point).
operator    category    expression        result
+        binary        var1=var2+var3;        var1 is assigned value that is sum of var2 and var3.
-        binary        var1=var2-var3;        var1 is assigned value that is value of var3 subtracted from var2.
*        binary        var1=var2*var3;        var1 is assigned value that is product of var2 and var3.
/        binary        var1=var2/var3;        var1 is assigned value that is value of var2 divided by var2.
%        binary         var1=var2%var3;        var1 is assigned value that is remainder when var2 divided by var2.
+        unary        var1=+var2;        var1 is assigned value of var2
-        unary        var1=-var2        var1 is assigned value of var2 multiplied by -1.
++        unary        var1=++var2;        var1 is assigned value of var2+1
--        unary        var1=--var2;        var1 is assigned value of var2-1
++        unary        var1=var2++;        var1 is assigned value of var2.Then var2 is incremented by 1.
--        unary        var1=var2--;        var1 is assigned value of var2.Then var2 is decremented by 1.
Operator used with string.
+        binary         var1=var2+var3;        var1 is assigned value that is concatenation of two strings stored in var2 and var3.

Write a program to print a string and two numbers,then some calculations.
(*)Create a new console application.
(*)Add the code.
static void Main(string[] args)
{
    double firstNumber,secondNumber;
    string userName;
    Console.WriteLine("Enter your name:");
    userName=Console.ReadLine();
    Console.WriteLine("Welcome {0}",userName!);
    Console.WriteLine("Now give me a number:");
    firstNumber=Convert.ToDouble(Console.ReadLine());
    Console.WriteLine("Now give me another number:");
    secondNumber=Convert.ToDouble(Console.ReadLine());
    Console.WriteLine("Sum of {0} and {1} is {2}.",firstNumber,secondNumber,firstNumber+secondNumber);
    Console.WriteLine("Subraction of {0} from {1} is {2}.",secondNumber,firstNumber,firstNumber-secondNumber);
    Console.WriteLine("Product of {0} and {1} is {2}.",firstNumber,secondNumber,firstNumber*secondNumber);
    Console.WriteLine("Result of dividing {0} by {1} is {2}.",firstNumber,secondNumber,firstNumber/secondNumber);
    Console.WriteLine("Remainder after dividing {0} by {1} and is {2}.",firstNumber,secondNumber,firstNumber%secondNumber);
    Console.ReadKey();
}
(*)Execute code.
display of output
Enter your name:
(*)Enter your name and press enter.
display of output
Enter your name:
keerthi
Welcome keerthi!
Now give me a number:
(*)Enter a number,press enter,then another number,then enter again.
display of output
Enter your name:
keerthi
Welcome keerthi!
Now give me a number:
32.76
Now give me another number:
19.43
Sum of 32.76 and 19.43 is 52.19
Subraction of 32.76 from 19.43 is 13.33
Product of 32.76 and 19.43 is 63.5268
Result of dividing 32.76 by 19.43 is 1.68605249613999
Remainder after dividing 32.76 by 19.43 is 13.33

Two concepts used in this program
User input-It use the syntax Console.ReadLine();
Type conversion-Use the command Convert.ToDouble() on string obtained by Console.ReadLine() to convert string into a double type.
You assign this number to firstNumber variable
firstNumber=Convert.ToDouble(Console.ReadLine());

Assignment operators
Operator    Category    Expression    Result
=        binary        var1=var2;    var1 is assigned value of var2.
+=        binary        var1+=var2;    var1 is assigned value that is sum of var1 and var2.
-=        binary        var1-=var2;    var1 is assigned value that is value of var2 subtracted from value of var1.
*=        binary        var1*=var2;    var1 is assigned value that is product of var1 and var2.
/=        binary        var1/=var2;    var1 is assigned value that is result of dividing var1 by var2.
%=        binary        var1%=var2;    var1 is assigned value that is remainder when var1 is divided by var2.
Operator precedence
When expression is evaluated,each operator is processed in sequence.Not evaluating operators from left to right.
(ex1)var1=var2+var3;
Here + operator acts before = operator.
(ex2)var1=var2+var3*var4;
Here * operator acts first,followed by + operator,finally by = operator.
(ex3)var1=(var2+var3)*var4;
Here paranthesis is evaluated first.
(ex4)*,/ with equal precedence are evaluated from left to right.
precedence    Operators
highest        ++,-- used as prefix,+,- unary
        *,/,%
        +,-
        =,*=,/=,%=,+=,-=
lowest        ++,-- used as suffix
   
Namespaces-Namespaces are containers  for categorizing application code items which is provided by .net framework .Keyword namespace can be used to explicity define namespace for a block of code..C# code by default is contained in global namespace.
Items in one namespace are accessible by other namespace by refering them by name,for that names must be qualified.Qualified names means it should contain all hierarchical informations.Qualified names use period characters(.)between namespace levels while refering.
Example-
namespace LevelOne
    {
        //code in LevelOne namespace
        //name "NameOne" defined
    }
    //code in global namespace
This code defines one namespace LevelOne and a name in this namespace.
DEfined name in code is refered from code inside namespace by name NameOne.
Defined name in code is refered from code inside namespace by name LevelOne.NameOne.
Nested namespace-Within a namespace you can define another namespace.Nested namespace are also refered using periods to classify each level.
Example-
namespace LevelOne
    {
        //code in LevelOne namespace
        namespace LevelTwo
            {
                //code in LevelOne.LevelTwo namespace
                //name "NameTwo" defined
             }
    }
//code in global namespace
Same name defined in difeerent namespaces
Example
namespace LevelOne
{
    //name "NameThree" defined
    namespace LevelTwo
    {
        //name "NameThree" defined
    }
}
Here name NameThree is defined in LevelOne and LevelTwo namespaces.Here same NameThree is refered by names LevelOne.NameThree and LevelOne.LevelTwo.NameThree independently.
using statement in namespace
To simplify access to name defined in a namespace using statement is used.
Example
namespace LevelOne
{
    using LevelTwo;
    namespace LevelTwo
        {
        //name NameTwo defined
        }
}
Here code in LevelOne namespace can now refer to LevelTwo.NameTwo by simply using NameTwo.This can cause clashes if identical name used in different namespaces.
So here alias for a namespace is provide for using statement.
Example
namespace LevelOne
{
    using LT=LevelTwo;
    //name NameThree defined
    namespace LevelTwo
        {
        //name NameThree defined
        }
}
Here code in LevelOne namespace can now refer to LevelOne.NameThree by simply using NameThree.And code in LevelOne namespace can now refer to LevelOne.LevelTwo.NameThree by simply using LT.NameThree.
Example
namespace LevelOne
{
    using LT=LevelTwo;
    //name NameThree defined
    namespace LevelTwo
        {
        //name NameThree defined
        }
}
In preceding code global namespace can't use LT.NameThree. Here code in global namespace and LevelOne namespace can use LT.NameThree.
Exanple-

using LT=LevelOne.LevelTwo;
namespace LevelOne
{
    //name NameThree defined
    namespace LevelTwo
        {
        //name NameThree defined
        }
}


























   

























    

























































 








































































What type of applications can you write with C#.

You know .net framework has no restriction on types of applications,so since C# uses .net framework it has no restriction too.Common application types are windows

application,web applications and web services.

windows application-These are applications having familiar windows look and feel.It is made by windows forms module of .net framework.(windows forms module is a

library of controls susch as buttons,toolbars,menus etc.. which is used to build a windows user interface(UI)).

Web applications-These applications are web pages which can be viewed by any browser.It is dynamically generating web content by .net framework.This section of .net

framework called as asp.net(ie,Active Server Pages.NET).

Web services-These are distributed applications,here data are exchanged virtually over internet with no restriction in language or system it resides.

ADO.NET-All These applications require database access achieved by ADO.NET(Active Data Pages.NET)of .net framework.
Tools used for creating network components,outputting graphics,performing mathematical tasks etc by all applications as per need.

Tuesday 4 March 2014

How C# is executed?



C # is executed when converted into a language understood by target operating system.This code is called native code.This compilation is a two stage process.When code using .net framework is compiled first,it is converted into (microsoft intermediate language code)MSIL.This comiplation is done by VS.Just In Time compiler compiles MSIL into native code.Here MSIL is independent of machine,OS,CPU.

Explain visual studio with features.

It is the environment which support many languages like c#,c++,visual basic etc. and with ease .net features can be integrated into your code.
The code created will be entirely C# but will use .net framework and you can make use of additional tools in VS when necessary.

Main features of VS is -

Main window contain a start page by default when VS is started.It is the place where all codes will be displayed.

Toolbars is above the main window.It is pops up when mouse mouse over it.Its function range from saving and loading files to building and running projects to dubbing projects.

Server explorer is selectable via View->server explorer from menu option.It provide access to data sources,server settings,services etc.

Solution explorer is selectable via View->solution explorer from menu option.
It displays various view of projects in a solution ie,what files they contain and what is contained in those files.

Properties window is selectable via View->properties window from menu option.It provide detailed view of contents in a project and allow to perform additional configuration of individual elements.
Error list window is selectable via View->Error list menu option.It displays error,warning and other information related to projects.It updates continuously,although some information will appear only when a project is compiled.

How to write applications using .net framework.


Writing application means writing code on any language(like C#,C++,VB,J# etc,,) that support .net framework using .net code library.

Explain .net framework.



It is a software framework.It is developed by microsoft.It runs on microsoft windows operating system.It was released on 2002.It has library of codes which consist of different modules which can be used from any language(like C++,C#,VB,J SCRIPT etc) to create applications(like WEB,WINDOWS,CONSOLE,WEB SERVICES etc) without any restriction.You can use portions of it depending on results you want to achieve.

Friday 28 February 2014

Explain types of function with example.


Types of function

1)without arguments and return values-Here neither the data is passed from calling function nor the data is sent back from called function.
The function is executed,they print result in same block.Such type is used for printing messages,drwa a line or split line etc.

Write an example of function without argument and return values.

#include<stdio.h>
#include<conio.h>
void main()
{
    void a(),b(),c();
    a();   //Here main() function calls 3 functions//
    b();
    c();
}

void a()
{
    printf("\n A");
}
void b()
{
    printf("\n B");
}
void c()
{
    printf("\n C");
}
Output
ABC

2)with arguments but without return values-The arguments are passed to the called function,but no result is sent back.

write an example of function with arguments and no return values.

#include<stdio.h>
#include<conio.h>
main()
{
    int datee(int,int,int);
    int d,m,y;
    clrscr();
    printf("Enter date:");
    scanf("%d \t %d \t %d",&d,&m,&y);
    datee(d,m,y);
    return 0;
}
datee(int x,int y,int z)
{
    printf("Date=%d/%d/%d",x,y,z);
}
Output
Enter date:11 2 2013
Date=11/2/2013

3)with arguments and return values-The arguments are passed to called fucntion and result is sent back to calling function.

write an example of function with arguments and return value.

#include<stdio.h>
#include<conio.h>
main()
{
    int datee(int,int,int);
    int d,m,y;
    clrscr();
    printf("Enter date:");
    scanf("%d \t %d \t %d",&d,&m,&y);
    t=datee(d,m,y);
    printf("Tomorrow=%d/%d/%d",t,m,y);
    return 0;
}
datee(int x,int y,int z)
{
    printf("Today=%d/%d/%d",x,y,z);
    return(++x);
}
Output
Enter date: 12 2 2013
Today=12/2/2013
Tomorrow=13/2/2013

4)without arguments and with return values-No arguments are passed to called function,but called function returns values.
It reads values from keyboard.

write an example of function without arguments and with return values.

#include<stdio.h>
#include<conio.h>
main()
{
    int sum,s
    clrscr();
    s=sum();
    printf("\n Sum=%d",s);
}
sum()
{
    int x,y,z;
    printf("\n Enter 3 values:");
    scanf("%d %d %d",&x,&y,&z);
    return (x+y+z);
}
Output
Enter 3 values: 3 4 5
Sum=12

Explain return statement with example.

Return statement
Itis used to return value to calling function.
It is used for exit from called function to calling function.
When it is executed it always returns 1.
Absence of return statement indicates no value is returned.Such functions are called void.
Next statement following return statement willnot be executed.

The return statement can be used in different ways-

return;
It returns always 1   

return(expression);
example-
return(a+b+C)
if such a statement is executed then expression within parenthesis is first solved and result obtained is returned.

Multiple return statement within a function-
example-
if(a>b)
return a;
else
return b;

return(&p)-It returns address of the variable.
return(*p)-It returns value of variable through pointer.
return NULL-It return NULL value.

Write a program to show return statement in different ways.
#include<stdio.h>
#include<stdio.h>
main()
int pass(int);
int x,y;
clrscr();
printf("Enter value of x:");
scanf("%d",&x);
y=pass(x);
switch(y)
{
case 1:
printf("Returned value is %d",y);
break;
default:
printf("Cube of x is %d",y);
}
return NULL;
}

pass(a)
{
if(a==0)
return;
else
return(a*a*a)
}
Output
Enter value of x:5
Cube of x is 125

Use of Local and global variable in function with example

Local and global variable
Local variable is defined within the body of the fucntion.Other function cannot access these variables.
Global variables-These are defined outside main () fucntion.Mulitiple functions can use them.

Write a program to show local variables.
#include<stdio.h>
#include<conio.h>
main()
{
    int a=10,b=20;
    clrcsr();
    printf("a=%d , b=%d",a,b);
}
func()
{
    int a=20,b=10;
    printf("a=%d b=%d",a,b);
}
Output
a=10,b=20
a=20,b=10
//here variable a and b are defined in both functions,There effect is only within the function in which they are defined//

Write a program to show global variables.
#include<stdio.h>
#include<conio.h>
int a =10,b=10;
main()
{
    clrcsr();
    printf("a=%d , b=%d",a,b);
    func();
    printf("a=%d , b=%d",a,b);
}
func()
{
   
    a++;   
    b--;
}
Output
a=10  ,b=10
a=11  ,b=9

Explain function with example.

Function-A function is a sub block with one or two statments which perform a task when called.Whenever a fucntion is called control passes to called function from calling function.Control returns back to calling function only when execution is done.The values of actual arguments are passed to formal arguments by calling function.
The function performs on formal arguments.
Syntax
functionname(arguments)
    {
    local variable declaration;
    stmt;
    return value;
    }
Write a program to show how a function is called.
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int x=1,y=2,z;
z=add(x,y); //calling function with actual arguments x,y//
printf("z=%d",z);
}
add(a,b)
{
return(a+b);//called function with formal arguments a,b//
}

Friday 31 January 2014

Explain strchr() and strstr() function with example.

strchr() function-This function returns pointer to a position of the first occurence of specified character in the given string.
syntax
chp=strchr(string,ch)   
chp is the pointer,ch is the character to be find in the string

Write a program to find a character in the string using strchr() function.

#include<stdio.h>
#include<conio.h>
main()
{
char string[10],*chp,ch;
clrscr();
printf("Enter the string");
gets(string);
printf("\n Enter the character to be find in the string:");
ch=getchar();
chp=strchr(string,ch);
if(chp)
    {
    printf("\n Character %c is found in the string",ch);
    }
        else
    {
    printf(""\n Character %c is not found in the string",ch);
    }
}
Output
Enter the string:Hello Begginers
Enter the character to be find in the string:r
Character r is found in the string

strstr() function-This function finds the second string in the given string.
syntax
strstr(str
ing1,string2)

Write a program to find a character in the string using strchr() function.

#include<stdio.h>
#include<conio.h>
main()
{
char string1[10],string2[10],*chp;
clrscr();
printf("Enter the first string");
gets(string1);
printf("\n Enter the second string to be found in the first string:");
gets(string2);
chp=strtr(string1,string2);
if(chp)
    {
    printf("\n second string %s is found in the first string",string1);
    }
        else
    {
    printf(""\n second string %s is not found in the first string",string2);
    }
}
Output
Enter the first string:Hello Begginers
Enter the second string to be found in the first string:Hello
second string Hello is found in the first string

Wednesday 29 January 2014

Explain strdup() function.

strdup() function-This function is used for duplicating the string at allocated memory which is pointed by a pointer variable.
syntax
dup1=strdup(s1) ,where s1 is string and dup1 is pointer
Write a program to enter a string and get its duplicate with strdup() function.
#include<stdio.h>
#include<conio.h>
main()
{
    char string[10],dup1[10];
    clrscr();
    printf("Enter the string:");
    gets(string);
    dup1=strdup(string)
    printf("\n Original string %s \n Duplicate string %s:",string,dup1);
}
Output
Enter the string:Good Day
Original string Good Day
Duplicate string Good Day
   
   



 

Explain strlwr(),strupr() function with example.

strlwr() function-This function converts any string to a lower case.
syntax
strlwr(upper);

Write a program to convert uppercase string to lowercase.
#include<stdio.h>
#include<conio.h>
main()
{
    char upper[10];
    clrscr();
    printf("Enter the string in uppercase:");
    gets(upper);
    printf("After strlwr(): %s",strlwr(upper));
}
Output
Enter the string in uppercase: ABCD
After strlwr(): abcd


strupr() function-This function converts any string to a upper case.
syntax
strupr(lower);

Write a program to convert lowercase string to uppercase.
#include<stdio.h>
#include<conio.h>
main()
{
    char lower[10];
    clrscr();
    printf("Enter the string in lowercase:");
    gets(lower);
    printf("After strupr(): %s",strupr(lower));
}
Output
Enter the string in uppercase: abcd
After strlwr(): ABCD

Explain stricmp(),strcmp(),strncmp() function.

stricmp() function-This function compares between two strings,it doesn't discriminates between lower and upper case.
syntax
stricmp(source string,destination string)

Write a program to compare between two strings.
#include<stdio.h>
#include<conio.h>
main()
{
    char s1[10],s2[10];
    int diff;
    clrscr();
    printf("Enter the source string:");
    gets(s1);
    printf("Enter the destination string:");
    gets(s2);
    diff=stricmp(s2,s1);
    if(diff==0)
        {
            printf("Two strings are identical");
        }
        else
        {
            printf("Two strings are not identical");
        }
}
Output
Enter the source string:HELLO
Enter the destination string:hello
Two strings are identical


strcmp() function-This function compares between two strings,it does discriminates between lower and upper case.
syntax
stricmp(source string,destination string)

Write a program to compare between two strings.
#include<stdio.h>
#include<conio.h>
main()
{
    char s1[10],s2[10];
    int diff;
    clrscr();
    printf("Enter the source string:");
    gets(s1);
    printf("Enter the destination string:");
    gets(s2);
    diff=strcmp(s2,s1);
    if(diff==0)
        {
            printf("Two strings are identical");
        }
        else
        {
            printf("Two strings are not identical");
        }
}
Output
Enter the source string:HELLO
Enter the destination string:hello
Two strings are not identical

strncmp() function-This function compares between two strings upto specified length.
syntax
stricmp(source string,destination string,n)

Write a program to compare between two strings upto specified length.
#include<stdio.h>
#include<conio.h>
main()
{
    char s1[10],s2[10];
    int n,diff;
    clrscr();
    printf("Enter the source string:");
    gets(s1);
    printf("Enter the destination string:");
    gets(s2);
    printf("Enter length upto which comparison is to be made");
    scanf("%d",&n);
    diff=strcmp(s2,s1,n);
    if(diff==0)
        {
            printf("Two strings are identical upto %d characters");
        }
        else
        {
            printf("Two strings are not identical");
        }
}
Output
Enter the source string:HELLO
Enter the destination string:hello
Two strings are not identical

Explain strcpy() and strncpy() function with example.

strcpy() function-It copies contents of one string to another.
Syntax
strcpy(destination,source)  ,where source string is copied to destination string.

Write a program to copy contents of one string to another by using strcpy().
#include<stdio.h>
#include<conio.h>
main()
{
    char s1[10],s2[10];
    clrscr();
    printf("Enter the string:");
    gets(s1);
    strcpy=(s2,s1);
    printf("\n Original string :%s",s1);
    printf("\n Duplicate string :%s",s2);
}
Output
Enter the string:Ragu
Original string:Ragu
Duplicate string:Ragu

strncpy() function-This function copies specified length of characters from source to destination string.
syntax
strncpy(destination,source,n) ,where n is the specified length

Write a program to copy source string to destination string with given length.
#include<stdio.h>
#include<conio.h>
main()
{
    char s1[10],s2[10];
    int n;
    clrscr();
    printf("Enter the source string:");
    gets(s1);
    printf("Enter the destination string:");
    gets(s2);
    printf("Enter number of characters to be replaced in destination string:");
    scanf("%d"&n);
    strcpy=(s2,s1,n);
    printf("\n Original string :%s",s1);
    printf("\n Duplicate string :%s",s2);
}
Output
Enter the source string:Wonderful
Enter the destination string:beautiful
Enter number of characters to be replaced in destination string:6
Enter the source string:Wonderful
Enter the destination string:wonderful

Explain strlen() function.

strlen() function-It counts number of characters in a string.
Syntax
l=strlen(string)   ,where l reads the count of characters

Write a program to read a string through keyboard.Determine length of the string.

#include<stdio.h>
#include<conio.h>
main()
{
    char string[10];
    int string,l;
    printf("Enter the string:");
    gets(string);
    l=strlen(string);
    printf("Entered name is %s and its length is %d",string,l);
}
Output
Enter the string:
Rohini
Entered string is Rohini and its length is 6

Explain string with different formats.

String
Group of characters,digits,symbols enclosed within quotation marks are called strings.The C compiler inserts NULL(\0) character automatically at end of the string.
Different formats of initialization of string
char name[]="INDIA";
or
char name[]={'I','N','D','I,'A','\0'};
or
char name[]={{I},{N},{D},{I},{A}};

Write a program to print "INDIA" by using different formats of initialization of array.
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
   {
    char a1[]={'I','N','D','I''A','\0'};
    char a2[]="INDIA";
    char a3[6]={{I},{N},{D},{I},{A}};
    clrscr();
    printf("\n Array1=%s",a1);
    printf("\n Array2=%s",a2);
    printf("\n Array3=%s",a3);
   }
Output
Array1=INDIA
Array2=INDIA
Array3=INDIA

Write a program to display string 'PRABHAKAR 'using different formats.
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char a[]="PRABHAKAR";
clrscr();
printf("  %s  \n ",a);
printf(" %.5s \n ",a);
printf(" %.8s \n ",a");
printf(" %.15s \n ",a);
printf(" %-10.4s  \n",a);
printf(" %11s \n ",a);
}
Output
PRABHAKAR
PRABH
PRABHAKA
PRABHAKAR
PRAB
PRABHAKAR

Print elements of character array given with while loop (help of Null character).

#include<stdio.h>
#include<conio.h>
main()
{
    char a[]="Have a nice day";
    int i=0;
    clrscr();
    printf("Elements of the array:");
    printf("\n");
    while(a[i]!='\0')
        {
        printf("  %c ",a[i]);
        i++;   
        }

}
Output
Elements of the array:
Have a nice day

Explain two dimensional array with example.Write a program to print a matrix and its transpose.

Two dimensional array-It is a collection of a number of one-dimensional arrays.Each row can be thought of as a one-dimensional array.
It is thought as a rectangular display of elements with rows and columns.
        column1        column2     column3
row1        x[0][0]        x[0][1]        x[0][2]
row2        x[1][0]        x[1][1]        x[1][2]
row3        x[2][0]        x[2][1]        x[2][2]

Write a program to display elements of two dimensional array.
#include<stdio.h>
#include<conio.h>
main()
{
int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};
printf("Elements of an array");
for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            {
            printf(" \t %d ",a[i][j]);
            }
        printf(" \n ")
           
    }
   Output
   1 2 3
   4 5 6
   7 8 9

Write a program to enter elements of a matix with order 3x3 and print the matrix.


#include<stdio.h>
#include<conio.h>
main()
{
int a[3][3];
printf("Enter elements of an array");
for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            {
            scanf(" \t %d ",&a[i][j]);
            }
        printf("\n")
    }
for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            {
            printf(" \t %d",a[i][j]);
            }
        printf("\n")
    }
       Output
    Enter elements of an array
       1 2 3
       4 5 6
       7 8 9
Write a program to enter elements of a matix with order 3x3 and display its transpose.

#include<stdio.h>
#include<conio.h>
main()
{
int a[3][3];
printf("Enter elements of an array");
for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            {
            scanf(" \t %d ",&a[i][j]);
            }
        printf("\n")
    }
for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            {
            printf(" \t %d",a[i][j]);
            }
        printf("\n")
    }
printf("Transpose of matrix");
for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            {
            printf(" \t %d",a[j][i]);
            }
        printf("\n")
    }
}
    Output
Enter elements of an array
    1 2 3
    4 5 6
    7 8 9
Transpose of matrix
    1 4 7
    2 5 8
    3 6 9

Explain array with one dimensional array example

Array-It is a set of unique variables with same data type located in continous memory locations.

Declaration of array
int a[5];
Here set of 5 elements with integer data type is stored in the array a.

initialization of array
int a[5]={1,2,3,4,5}

Important point-
(a)Array elements are called by array names.
array element 1 called by array name a[0],array element 2 called by array name a[1],array element 3 called by array name a[2],
array element 4 called by array name a[3],array element 5 called by array name a[4]
(b)Any particular element of an array can be modified seperately without disturbing other elements.
Example-
int a[5]={1,2,3,8,5}
To carry out this task the statement a[3]=4 can be used to change element 8 to 4 from array a[5].
(c)Starting memory location of array a assumed 2000 then next element located in 2002 because each integer element requires 2 bytes.
So character-1 byte,integer-2bytes,float-4 bytes,long-4 bytes,double-8 bytes.

Character array-They are called as strings.Here NULL('\0') character is automatically added at the end.
NULL acts as an end of the character array when compiler reads it .

Write a program to display elements of one dimensional character array with address.
#include<stdio.h>
#include<conio.h>
main()
{
int i=0;
char name[6]={'A','R','R','A','Y'};
printf("Character and memory location");
while(name[i]!='\0')
    {
        printf("    \n  %c \t %u   ",name[i],&name[i]);
        i++;
    }
}
Output
Character and memory location
A    4054
R    4055
R    4056
A    4057
Y    4058

Wednesday 22 January 2014

Explain each decision statements with example.

It checks the condition,then executes its sub block.

if statement-It checks the condition,if condition is true then executes its sub block.
Otherwise when condition is false,the compiler skips lines within the if block.
It is enclosed in curly braces.
Use curly braces even with a single statement.

syntax
if(condition is true)
{
statement;
}

Write an example for if statement checking if entered number is less than 10.
#include<stdio.h>
#include<conio.h>
main()
 {
  clrscr();
  int a;
  printf("Enter the number:");
  scanf("%d",&a);
  if(a<10)
   {
    printf("Entered number is less than 10");
    else
    printf("Entered number is not less than 10");
   }
}

Output

Enter the number:5

Entered number is less than 10

if else statement-It has two blocks.if condition is true first block is executed otherwise if condition is false else block is executed.

syntax
if(condition is true)
  {
   statement1;
  }
 else
  {
  statement2;
  }

Write example for if else statement.Read values of a,b,c Add and check after addition if it is in the range of 100 & 200 or not.
 

#include<stdio.h>
#include<conio.h>
main()
 {
  clrscr();
  int a,b,c;
  printf("Enter the numbers a b c:");
  scanf("%d %d %d",&a.&b,&c);
  printf("\n a=%d b=%d c=%d",a,b,c)
  d=a+b+c;
  if(d>=100 & d<=200)
    {
    printf("\n Sum is in between 100 and 200");
    else
    printf("\n Sum is not in between 100 and 200");
    }
 }

Output
Enter the numbers a b c: 50 50 20
a=50 b=50 c=20
Sum is in between 100 and 200

nested if statement-If condiion is true then first block is executed.Otherwise in else block condition is checked with the if statement..

syntax
if(condition is true)
  {
   statement1;
  }
   else if (condition is true)
              {
              statement2;
              }
            else
              {
              statement3;
              }

Write an example for nested if else statement where find largest among 3 numbers.

#include<stdio.h>
#include<conio.h>
main()
 {
  clrscr();
  int a,b,c;
  printf("Enter the numbers a b c:");
  scanf("%d %d %d",&a.&b,&c);
  printf("\n a=%d b=%d c=%d",a,b,c)
 
  if(a>b)
    {
      if(a>c)
          {
          printf("\n Largest number is %d",a);
          }
          else
          {
          printf("\n  Largest number is %d",c ");
          }

    }
  else
    {
       if(c>b)
           {
           printf("\n Largest number is %d",c);
           }
           else
           {
          printf("\n  Largest number is %d",b ");
           }

   }
 
Output

Enter the numbers a b c:10 20 30
Largest number is 30

break statement-break skips from the loop in which it is defined and then goes automatically to first statement after loop.

continue statement-It is used for continuing in next iteration of loop statement and it skips the statement after this statement.

goto statement-Where label is the position where the control is to be transfered.

syntax
goto label;

where label name must start with any character

Write an example of goto statement checking the number whether even or odd.
   
    #include<stdio.h>
    #include<conio.h>   
    main()
     {
    int a;
    clrscr();    
    printf("Enter the number:");
    scanf("%d %d",&a);
      if(a%2==0)
             {
             goto even:
             }
               else
             {
             goto odd;
             }
    even:
    printf("\n %d is even");
    return;
    odd:
    printf("\n %d is odd");
    }

       Output
     
 Enter the number:4
       4 is even

Switch statement-Used to make a choice from a number of options.It need only one argument of any data type,which is checked with many case options.
   
    syntax
    switch(variable)
        {
        case constant a:
        statement;
        break;
        case constant b:
        statement;
        break;
        default:
        statement;
        }
Write an example for switch statement showing functions like addition ,subtraction
,multiplication,division,remainder.
    #include<stdio.h>
    #include<conio.h>
    main()
     {
          clrscr();
          int a,b,c,ch;
        printf("0 \n TERMINATED BY CHOICE");
          printf("1 \n FOR ADDITION");
          printf("2 \n FOR SUBTRACTION");
          printf("3 \n FOR MULTIPLICATION");
          printf("4 \n FOR DIVISION");
          printf("5 \n FOR REMAINDER");
          printf("6 \n FOR EXIT");
          printf("\n ENTER YOUR CHOICE")
        scanf("%d",&ch);
            if(ch<=6 && ch>=0)
                {
                    printf("Enter 2 numbers:");
                    scanf("%d %d",&a,&b);
                }
        switch(ch)
        {
       
        case 1:
        c=a+b;
        printf("ADDITION:%d",c);
        break;
       
        case 2:
        c=a-b;
        printf("SUBTRACTION:%d",c);
        break;

        case 3:
        c=a*b;
        printf("MULTIPLICATION:%d",c);

        case 4:
        c=a/b;
        printf("DIVISION:%d",c);
        break;
       
        case 5
        c=a+b;
        printf("REMAINDER:%d",c);
        break;

        case 0:
        printf("\n TERMINATED BY CHOICE");
        exit();
        break;
        default:
        printf("Invalid choice");
           }
    }
       

Thursday 16 January 2014

Explain increment operator with example.

The operator ++ adds one to its operand.
x=x+1 can be written as x++ or ++x
If ++ is used as prefix then value of variable will be increased first.
If ++ is used as suffix then value of variable will be increased later.

Write a program to show effect of increment operator as a prefix.

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int x=10,y=10,z;
z=x* ++y;  /* y is increased first then used for multiplication */
printf("Value of z = %d",z);

output
Value of z=110


Write a program to show effect of increment operator as a suffix.

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int x=10,y=10,z;
z=x*y++;  /* First multiplication then y is increased*/
printf("Value of z = %d",z);

output
Value of z=101


Write a program to show '&' operator.

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int x=2;
float y=2;
printf("Address of x=%u,Address of y=%u",&x,&y);
}

output
Address of x=4066,Address of y=25096

Explain conditional operator with example.

Conditional operator
Here if given condition is true then exp1 is evaluated else exp2.

syntax
condition?(exp1) : (exp2);

Write a program to show conditional operator
#include<stdio.h>
#include<conio.h>
main
int x=2;
()
{
clrscr();
printf("Result=%d",1==2?4:5);
}

output
Result=5

Explain comma operator with example.

It is used to separate 2 or more expressions.
It has lowest priority among all operators.

Write a program to show comma operator

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
printf("Addition =%d \n Subtraction=5d",3+2,3-2);
}
output
Addition=5
Subtraction=1


Tuesday 14 January 2014

Explain Logical operator with example.

It check logical relation between two expressions.If relation is true it returns 1 otherwise 0.
The operators are logical AND(&&),logical OR(||),logical NOT(!=).

Write a program to print logic 1 if input character is capital otherwise 0.

#include<stdio.h>
#include<conio.h>
main()
{
char x;
int y;
clrscr();
printf(" \n Enter a character ");
scanf(" %c ",&x);
y=( x>=65 && x<=90 ? 1:0 );
printf(" Y : %d ",y );


}

Output
Enter a character : A
Y : 1
Enter a character : a
Y : 0

Write a program to display 1 if inputted number is between 1-100 otherwise 0.Use logical AND(&&) operator.

#include<stdio.h>
#include<conio.h>
main()
{
char x;
int y;
clrscr();
printf(" \n Enter a number:");
scanf(" %c ",&x);
y=( x>=1 && x<=100 ? 1:0 );
printf(" Y : %d ",y );
}

output
Enter a number:5
Y= 1


Write a program to display 1 if inputted number is either 1  or 100 otherwise 0.Use logical OR(||) operator.

#include<stdio.h>
#include<conio.h>
main()
{
char x;
int y;
clrscr();
printf(" \n Enter a number:");
scanf(" %c ",&x);
y=( x==1 || x==100 ? 1:0 );
printf(" Y : %d ",y );
}

output
Enter a number:5
Y=0
Enter a number:100
Y=1

Write a program to display 1 if inputted number is between 1-100 otherwise 0.Use logical AND(&&) operator.

#include<stdio.h>
#include<conio.h>
main()
{
char x;
int y;
clrscr();
printf(" \n Enter a number");
scanf(" %c ",&x);
y=( x>=1 && x<=100 ? 1:0 );
printf(" Y : %d ",y );
}

output
Enter a number:5
Y= 1

Write a program to display 1 if inputted number is not 100 otherwise 0.Use logical NOT(!=) operator.

#include<stdio.h>
#include<conio.h>
main()
{
char x;
int y;
clrscr();
printf(" \n Enter a number");
scanf(" %c ",&x);
y=( x!=100 ? 1:0 );
printf(" Y : %d ",y );
}

output
Enter a number:100
Y= 0

Explain Relational operator with example.

It check relation between two constant values.If relation is true it returns 1 otherwise 0.
The operators are >=,<=,<,>,==,!=.


Write a program to use all relational operator and display thier return values.

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
printf("  \n Condition : Return value  ");
printf("  \n 10!=10 :%5d  ",10!=10);  /* not equal to */
printf("  \n 10<=10 :%5d  ",10<=10);  /* less than or equal too */
}

Output

Condition : Return Value
   10!=10 : 0
   10<=10 : 1

Explain Input and Output function in C



I/O function

Input function-A program takes data through input function.
Output function-A program displays result on screen through output function

2 Types

a)  Formatted b) Unformatted function

Formatted function-It read and write all types of data types.

2 Types

a) printf( ) b) scanf( )

printf() statement-It prints data values to the console.It need conversion symbols to print  variable values.Here escape sequence \n is used for new line.

scanf() statement-It reads data values.It need conversion symbols to read variable values.
The '&' address operator is used to indicate memory location of variable,so that value read should be placed in that location.

Unformatted function-It work with only character data type.
 Types
(a) getchar( ) (b) putchar( ) (c) getch( ) (d) getche ( ) (e) gets( ) (f) puts( )

Friday 10 January 2014

Explain arithematic operator in C

binary arithmetic operator-This is used for calculation between two constant values.They are +,-,*,/,%.
unary arithmetic operator-This is used for calculation with one value.They are unary minus(-),increment(++),decrement(--),address operator(&),sizeof.

Write a program to show effect of increment operator as a prefix and suffix.

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,x=10,y=20;
clrscr();
a=x * ++y;  /* increment as prefix,here  value of y is increased  and then used for multiplication*/
c=x*y;
b=x * y++; /*increment as suffix,here  after multiplication y is increased */
d=x*y;
printf(" \n %d %d ",a,c,b,d);
}

output


210 210 200 210

address (&) operator-It prints address of variable in memory.
sizeof() operator-It gives bytes occupied by variable.

Write a program to use address (&) operator and sizeof() operator.


#include<stdio.h>
#include<conio.h>
main()
{
int x=2;
float y=2;
clrscr();
printf("\n sizeof(x)=%d bytes,sizeof(y)=%d bytes ",sizeof(x),sizeof(y));
printf("\n Address of x=%u,Address of y=%u",&x,&y);
}


output
sizeof(x)=2,sizeof(y)=4
Address of x=4066,Address of y=25096

Explain variable in C

Variable
A variable is a data name used for storing a data value.
Its value may change during execution.
It should not be a C keyword.
It may be a combination of uppercase and lowercase characters.
Ex-
sUm and SUM both are different.
It should start with a character not a digit
Declare variable
Its declaration should be done in declaration part of C program because it helps in allocating memory.
Syntax-
datatype variablename;
ex-
int age;
int a,b,c;
Initialize variable
Initialization and declaration of variable can be done in same line.
syntax-
datatype varaible = constant;
ex-
int y=2;
Constant variable
To make value of variable constant use keyword const before declaration
ex-
const int m=1;

Monday 6 January 2014

Explain data types in C

Data types 
They are used to define  variables before its use.As per need different data types are used in C.
For example
a)int is used to define integer numbers
{
int count;
count=4;
}
b)float is used to define floating point numbers
{
float miles;
miles=5.6;
}
c)double is used to define big floating point numbers,it reserves twice the storage for numbers.
{
double atoms;
atoms=25000;
}
d)char defines character
{
char letter;
letter='c';
These are common data types.Others are short,long,signed,unsigned.
short int<int<long int
float<double<long double
signed and unsigned
when a variable is declared as unsigned then negative range of data type is declared as positive.
example
unsigned long int c;
Memory size of different data types
short integer occupies memory of 2 bytes
long integer occupies memory of 4 bytes
signed and unsigned integer occupies memory of 2 bytes
float occupies memory of 4 bytes
double occupies memory of 8 bytes
character occupies memory of 1 byte