Powered by Blogger.

Text Widget

Featured

Recent Post

Follow

Popular Posts

Featured

Pages

Subscribe

Kamu Pasti Tertarik

Most Popular
Videos

MoreBaru diupdate

Gallery

story

Thursday, 7 January 2016

Basics of C program

Before proceeding to the languages in detail, let us have a short view on the datatypes used in C language.

Data types are the keywords used for representing the type of the variable. The data types can be classified as follows:

1. Fundamental Datatypes
2. Derived Datatypes

FUNDAMENTAL DATATYPES

Almost all of you knew about the fundamental datatypes. So, lets have a short revision.
1. int - used to represent integer data types. It occupies 4 bytes. ( on a 32 bit computer)
2. char - used to represent character data types. It occupies 1 byte.
3. float - used to represent decimal values. It occupies 4 bytes.

To find the size allocated for a variable, we can use the following code:

CODE:

#include
#include 
int main(){int a;char b;float c;double d;printf(“size of int data type:%d \n”,sizeof(a));printf(“size of char data type:%d \n”,sizeof(b));printf(“size of float data type:%d \n”,sizeof(c));printf(“size of double data type:%d\n”,sizeof(d));return 0;}                     

OUTPUT:

size of int data type:4size of char data type:1size of float data type:4size of double data type:8 

Here, we made use of a built-in function called sizeof(). This is used to know the actual size of a variable.

DERIVED DATATYPES:

Derived datatypes are those that are defined in terms of other datatypes (fundamental datatypes). They are:
1. Arrays
2. Structures
3. Pointers
4. Union

We will deal with these topics with examples later.

VARIABLES:

Variable is an identifier which is specified to hold a value of a particular datatype. This value may be changed during the execution of a program. It is declared as,

syntax: datatype variable = value;
eg: int a = 10;

CONSTANTS:

The value declared as constant cannot be changed during the execution of the program. It is declared as, 

syntax: const datatype variable = value;
eg: const int a=10;

STRINGS:

The sequence of characters are known as strings. There is no data type to define string. char datatype is used to define a string. A string is stored as an array of characters.

syntax: char variable[array_size];
eg: char a[10];

The array index varies from 0 to 9 for the size 10. The last byte stores the null character '\0'.

Tags: sizeof(), datatype, derived datatype, variables, constants, strings.
Copy Article URL:

No comments:

Post a Comment

Template By Way2Themes | Some Rights Reserved.