Sunday, September 25, 2011

C Programming Data Types : Part 1

Be The First To Comment
C has concept of data type which are used to define type of variable means a variable hold which type of data (i.e char,interger,float e.t.c).
so there are 6 data types available in the C are.
1.) Integer.
2.) Char .
3.) Float.
4.) Double.
5.) void .
6.) Enum.

Integer

Integer datat ype are used to define integer type.

Int Variable name

Example.

int val;

Char

char defines characters.

Example. Char val;
val=INDIA;

Double

Double use for large floating point variables.

Example.

Double val;

val=250000;

Enumerated

A enum type is integer type that allows to give the name to certain values.

Example.

enum language { english, french, spanish = 4, german, chinese };

If value assigned to the variable then that value for that variable is used .if not then the value of last variable + 1 is the value of that variable.

If no value is assigned to the variable then default value is used from 0.

english-0

french-1

spanish=4

german=5

chinese=6

Void

Void means "containing nothing"

void has no values therefore we can't use it to declare variable type.It is basically use to define the type of function like.

void main()

That's means the function main returning nothing.

Modifiers

Modifiers define the amount of memory allocated to the variable.

The type of modifiers are .
short
long
signed
Unsigned
short int >= int >= long int
float >= double >= long double
That means the value assigned by the short int is less than or equal to int .Similar the value assigned by the int is equal or less than value assigned by the long int.
If you want to check manually the ranges of integer and float then try the below code .
#include <stdio.h>
#include <limits.h>

void main()
{
printf("Signed char minimum value: %d \n", SCHAR_MIN );
printf("Signed char maximum value: %d \n", SCHAR_MAX );
printf("Unsigned char minimum value: %d \n", 0 );
printf("Unsigned char maximum value: %d \n", UCHAR_MAX );
printf("Char minimum value: %d \n", CHAR_MIN );
printf("Char maximum value: %d \n", CHAR_MAX );
printf("Signed short minimum value: %d \n", SHRT_MIN );
printf("Signed short maximum value: %d \n", SHRT_MAX );
printf("Unsigned short minimum value: %d \n", 0 );
printf("Unsigned short maximum value: %d \n", USHRT_MAX );
printf("Signed int minimum value: %d \n", INT_MIN );
printf("Signed int maximum value: %d \n", INT_MAX );
printf("Unsigned int minimum value: %u \n", 0 );
printf("Unsigned int maximum value: %u \n", UINT_MAX );
printf("Signed long minimum value: %ld \n", LONG_MIN );
printf("Signed long maximum value: %ld \n", LONG_MAX );
printf("Unsigned long minimum value: %lu \n", 0 );
printf("Unsigned long maximum value: %lu \n", ULONG_MAX );
printf("Signed long long minimum value: %lld \n", LLONG_MIN );
printf("Signed long long maximum value: %lld \n", LLONG_MAX );
printf("Unsigned long long minimum value: %lu \n", 0 );
printf("Unsigned long long maximum value: %llu \n", ULLONG_MAX );

getch();

}


Output



That's it i will continue this tutorial in next section too.

Saturday, September 24, 2011

What is the output of printf("%d")

Be The First To Comment


Ans:
printf ( "format string=""", list of="" variables="" ) ;
format string="" can contain,
%f for printing real values
%d for printing integer values
%c for printing character values

When i execute this instruction on dev c++ i got a garbage value .If you want to try this try the below code .

#include<stdio.h>
#include<conio.h>

int main()

{

printf("%d");
getch();

}

Introduction To C Language

Be The First To Comment

History


1.) The C language was developed by AT&T bell lab in early 1970s by Dennis Ritchie.
2.) It was based on early language of AT&T bell lab language called 'B' which is also based on BPCL.

Advantages


1.) C is general purpose language for an example
(COBOL is used for making business application and FORTRAN is used for scientific applications but we can use C Language for both).
2.) C is not very high level languages.You can use C to direct memory access,create bitwise operation and so on.
3.) C is not so high level language so the execution speed of C language is fast.

Use Of C


1.) C is use for wriiting software to control hardware.
2.)Unix and its derivatives are written in C language.
3.) Languages like perl and php are written in C languages.

Structure Of C


C mainly included two type of files
1.)Header File : This file have extension " .h " it includes methods,constants,macros e.t.c/
2.) Source file: This file have extension " .c " it includes your source code .
 

© 2011 Preparing For Software Interviews - Designed by Sudhir dudeja | TOS |Sitemap

About Us | Contact Us