Home » Programming » Languages » Story Details
Printable Version

Vriables types in C

by Manish Tewatia on Feb 01, 2012

In the C programming language data types refers to an extensive system for declaring variables of different types. The language itself provides basic arithmetic types and syntax to build array and compound types.
Comments: 0    Views: 149

Introduction

In the C programming language data types refers to an extensive system for declaring variables of different types. The language itself provides basic arithmetic types and syntax to build array and compound types. A variable is just a named area of storage that can hold a single value . The C language demands that you declare the name of each variable that you are going to use and its type, or class before you actually try to do anything with it.

A computer memory is made up of registers and cells which are capable of holding information in the form of binary digits 0 and 1 bits. This is the way information is stored in a memory just like we memorize numbers using 0 to 9. Collection of 8 bits is called a byte. Normally the CPU does not accessed memory by individual bits. Instead, it accesses data in a collection of bits, typically 8 bits, 16 bit, 32 bit or 64 bit. The amount if bits on which it can operate simultaneously is known as the word length of the computer. When we say that Pentium 4 is a 32 bit machine, it means that it simultaneously operates on 32 bit of data. Data is stored in the memory at physical memory locations. These locations are known as the memory address.  It is very difficult for humans to remember the memory addresses in numbers like 46735, so instead we name a memory address by a variable.

Variables  are a way of reserving memory to hold some data and assign names to them so that we don't have to remember the numbers like 46735 and instead we can use the memory location by simply referring to the variable. Every variable is mapped to a unique memory address.

Type of Variable : The Programming language C has two main variable types.

  1. Local Variables :  Local variables scope is confined within the block or function where it is defined. Local variables must always be defined at the top of a block. When a local variable is defined  it is not initialized by the system, you must initialize it yourself. When execution of the block starts the variable is available, and when the block ends the variable 'dies'.
  2. Global Variables : Global variable is defined at the top of the program file and it can be visible and modified by any function that may reference it.

Declaration of variables : In order to use a variable in C++, we must first declare it specifying which data type we want it to be. The syntax to declare a new variable is to write the specified of the desired data type (like int, bool, float...) followed by a valid variable identifier.
int  sum;
float average = 2.34;
char name = 'c';

Example : The simple example of a local variable used.

Code

main()
{
      int i=4;
      int j=10;
      i++;
      if (j > 0)
      {
                  printf("i is %d\n",i);
      }
      if (j > 0)
      {
         int i=100;
         printf("i is %d\n",i);     
      }
      printf("i is %d\n",i);   }
}

Post a Comment
*
DevExpress PowerBuilder Web Development Windows Development Languages Software Engineering Databases
iPhone Architecture Secutiry UML & Modeling Operating Systems Networking Testing
Graphics Design Project Management Hardware Open Source Games Development Business Intelligence Visual Studio LightSwitch 2011
MonoDevelop Visual Studio 2010 ASP.NET HTML, DHTML XML PHP JavaScript
Silverlight Web Services WCF Windows Forms WPF Windows Services Dynamic Link Libraries
ActiveX COM, DCOM, ATL C# VB.NET C++ F# Java
Pascal SQL Server Oracle DB2 MS-Access Windows Servers Windows
Linux Unix SAP LINQ .NET Framework ADO.NET Reporting
Crystal Reports SQL Server Reporting Services Igenda Reports Active Reports Adobe Fireworks Arrays & Collections Hosting
Future Trends Android Windows Phone Smart Devices Business M&A Investment & Funding
Web Browsers Internet Explorer Firefox Safari Common Entrepreneurs Students
Consulting Wiki Gadgets MobileMe iCloud iOS Social Media
Facebook Twitter LinkedIn Google+ Microsoft Kinect XBox
Wii Playstation DirectX i OS OS X CIO, CTO, CEO Windows 8
Web Design Expression Blend 4 Photoshop CS5 Creative Suite 5.5 Expression Web 4 Expression Studio 4 Creative Suite® 5.5 Design
Creative Suite 5.5 Web Creative Suite 5.5 Production Startups Funding M&A Laptops Smart Phones
Desktops Cameras & Camcorders Netbooks Tablets Virtualization Microsoft Surface WordPress
Software Products Cloud Computing Current Affairs Technology TV TV
Earnings XAML E-Commerce MonoTouch Mono for Android Deals Electronics
Mobile Phone Laptop Tablet Book Computer Press Releases Reviews
Products Books Companies Windows Azure SQL Azure Interviews Mac
Web Browsers Symbian Windows Forms WPF Windows Services HTML 5 Office 365
SharePoint 2010 Exchange Server Adobe Visual Studio 2012 iPad Flex / Flash Games
Windows 9
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName