Wednesday, February 23, 2011

Address of a variable in c


Location in a memory where a variable stores its data or value is known as address of variable. To know address of any variable c has provided a special unary operator & which is known as deference operator or address operator. It operator is only used with variables not with the constant. For example:



#include

int main(){

int a=5;

printf("Address of variable a is: %d",&a)

Definition of variable in c


Definition of variable in C programming language:


A variable is named location of data. In other word we can variable is container of data.




In real world you have used various type containers for specific purpose. For example you have used suitcase to store clothes, match box to store match sticks etc. In the same way variables of different data type is used to store different types

Identifier naming rule in c




In c any name is called identifier. This name can be variable name, function name, enum constant name, micro constant name, goto label name, any other data type name like structure, union, enum names or typedef name.




Rule 1: Name of identifier includes alphabets, digit and underscore.







Valid name: world, addition23, sum_of_number etc.






Invalid name: factorial#, avg value,

Value of variable in c language



Explanation of value of a variable in c programming language
by examples and questions and answers


Data which any variable keeps is known as value of variable. For example:



int a=5;



Here value of
variable a is five. Name of variable always returns value of the variable.



How to assign
any value to a variable:



C supports
eleven type of assignment operator to assign any value to

Declaration of a variable in c



Declaration of variables in c:



Declaration of
variables means to acknowledge the compiler only about variable name and its
data type with its modifiers but compiler doesn�t reserve any memory for the
variables.



In c we can
declared any variable with help of extern keyword while it has not initialized. Example of declaration:



(1) extern int a;



(2)extern struct student{

char *

Tuesday, February 22, 2011

do while loop in c



Explanation
of do while loop in c programming language by examples, questions and answers



It is also
called as post tested loop. It is used when it is necessary to execute the loop
at least one time. Syntax:



do {

Loop body

} while (Expression);



Example:



void main(){

int num,i=0;

clrscr();

do{


printf("To enter press 1\n");


printf("To exit press 2

Nested loop in c programming




A loop inside another loop
is known as nested loop. We can write any loop inside any loop in c i.e. we can
write for loop inside the loop or while loop or do while loop etc. For example:



(a)

#include

int main(){

int i,j,k;

for(i=0;i<3;i++){

for(j=0;j<3;j++){


printf(" %d",i+j);


}

}

return 0;

}



(b)

#include

int

while loop in c programming





While loop:



It is pre tested
loop. It is used when we have to execute a part of code in unknown numbers of
times.

Syntax:



while (Expression){

Loop body

}



Properties of while loop:



1. Task of the
expression is to check the condition. Loop will execute until condition is true
otherwise loop will terminate.



2. If any
expression returns zero then condition will false and if it

Looping in c



Explanation
of loops or looping in c programming language by examples and questions



Looping is the
process of repeating of same code until a specific condition doesn�t satisfy.
In c there are three types of loop:



(a)loop

(b)while loop

(c)do while



for loop:



This loop is
used when we have to execute a part of code in finite times. It is per tested
loop. Syntax of for loop:



for (

Break and continue keywords in c programming

Explanation
of break and continue in c programming language by examples and questions and
answers



break:



It is keyword of c
programming. Task of this keyword is to bring the control from out of the loop
in the case of looping. For example:



#include

int main(){

int i;



for(i=0;i<=4;i++){


printf("%d",i);

break;


printf("Label 1");

Monday, February 21, 2011

Array tutorials in c programming language by examples



Array
tutorials in c programming language by examples



An array is derived data type in c programming language which can store similar type of data in continuous memory location. Data may be primitive type (int, char, float, double�), address of union, structure, pointer, function or another array.



Example of array declaration:




int arr[5];



char arr[5];



float arr[5];



long

Sunday, February 20, 2011

java questions for viva


Java questions and answers for viva

(1)



public class Literal {

public static void main(String[] args) {

String str$="world";

char str_='X';

String $_=str$+str_;

System.out.print($_);



}

}



What will output when you compile and run the above code?



(a)world

(b)worldX

(c)world�X�

(d)Compiler error











Answer: (b)

Character literals questions on java and answer with solution

Objective types questions and answers of character literals in java


(1)



public class Literal {

public static void main(String[] args) {

char b ='\n';

int a=(int)b;

System.out.println(a);

}

}



What will output when you compile and run the above code?



(a)10

(b)11

(c)12

(d) Compiler error









Answer: (a)





(2)



public class Literal {

String literal questions on java and answer with solution




Objective type
questions of string literals and answers in java programming



(1)



public class Literal {

public static void main(String[] args) {

String a="c:\\tc\\bin";

System.out.println(a);

}

}



What will output when you compile and run the above code?



(a) c:\\tc\\bin

(b) c:\tc\bin

(c) c: c\bin

(d) Compiler error











Answer: (b)



(2)

variables questions on java with explanation


Questions on variables in java with answers


(1)



public class Test {

public static void main(String[] args) {

int a=5;

{

Integer b=10;

}

int c=a+b;

System.out.println(c);

}

}



What will output when you compile and run the above code?



(a)15

(b)5

(c)Compiler error

(d) Run time error











Answer: (c)



Automatic type promotion questions on java and answer with solution



Java objective questions on automatic type promotion and answers


(1)



public class TypeConversion {

public static void main(String[] args) {

{

final int a='\15';

System.out.println(a);

}

int a=25;byte b=0100;

a=a+b;

System.out.println(a);

}

}



What will output when you compile and run the above code

java scjp questions and answers



Objective type questions for preparation of scjp exam and answers in java



(1)




public class Loop {

public static void main(String[] args){



for(int i=0;false;i++){

System.out.println("java");

}

}

}



What will be output of above program?



(a)java

(b) Null

(c)It will not print anything.

(d)Compiler error













Answer: (d)



(2)

java questions for beginners



Simple java objective type questions and answers for beginners

(1)



public class Loop {

public static void main(String[] args){

int i=1;

int j=5;



for(;;){

System.out.println(j>>>i);

}

}

}



What will be output of the above java program?



(a)2

1

(b)2

1

0

(c)Infinite loop

(d)Compiler error













Answer:

Bitwise operators questions in java


Bit wise operators objective type questions and answers



(1)




public class BitwiseOpe {

public static void main(String[] args) {

int a=010;

Integer b=10;

double d=~a|(b=a)<<2+b;

System.out.print(d);

}

}



What will output when you compile and run the above code?



(a)32768.0

(b)-9.0

(c)1.0

(d)Compiler error













Answer: (b)


Operators questions in java



Questions on operators in java questions and answers

(1)



public class BitwiseOpe {

public static void main(String[] args) {

int a=010;

Integer b=10;

double d=~a|(b=a)<<2+b;

System.out.print(d);

}

}



What will output when you compile and run the above code?



(a)32768.0

(b)-9.0

(c)1.0

(d)Compiler error













Answer: (b)



(2)

static keyword interview questions in java


Interview questions of static keyword in java and answers

(1)



class StaticDemo {

static int a=0;

int b=++a;

static int c=++a;



public static void main(String[] args){

System.out.print(c);

}

}



What will be output of above program?



(a)0

(b)1

(c)2

(d)Compiler error













Answer: (b)



(2)



class StaticDemo {

int a=0;

super java keyword questions and answers


Question on java keyword super and answers

(1)



class Square{

static double pi=Math.PI;



static void area(double r){

System.out.print((int)pi*r*r);

}

}



class Cube extends Square{

static void area(double r){

System.out.print(6*(int)pi*r*r);

}

}



class SuperDemo extends Cube{

public static void main(String[] args) {

abstract class questions in java


Objective type questions on abstract class in java and answers

(1)



abstract class Abstract {



public static void main(String[] args){

System.out.print("It is abstract class");

}



static{

System.out.println("Why");

}

}



What will output when you compile and run the above code?



(a) Why

It is abstract class

(b) It is

Example of interface in java


Objective type questions on interface in java and answers

(1)



interface Apple{

float cost=9.5f;

public void display();

}



class Try implements Apple{



public static void main(String[] args){

Try t=new Try();

t.display();

}



public void display(){

System.out.print("cost of apple is :"+cost);

}

}



What will output when

Questions on enum data type in java and answers


Questions on enum data type in java and answers

(1)



enum Barcode{

a,b,c,d,e;

}



public class EnumTest {

public static void main(String[] args) {

System.out.println(Barcode.b);

}

}



What will output when you compile and run the above java code?



(a)1

(b)2

(c)b

(d)Compiler error













Answer:(c)



(2)



enum Barcode{

a,b,c,d,e;

}



public

break and continue questions in java



break and continue keyword questions and answers in java

(1)



Which of the following jump statement is not supported by java?



(a) break

(b) goto

(c) continue

(d) return







Answer: (b)



(2)



public class BreakDemo {

public static void main(String[] args){

int j=1;

for(int i=1;i<5;i++){

j*=i;{

break;

}

How to reverse a number in java


Java code to reverse a given number


import java.io.*;



class Test {

public static void main(String[] args) throws IOException {



int num,sum=0,r;

System.out.println("Enter a number");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());



while(num!=

GCD of two numbers in java


Java code to to find GCD or Greatest common divisor of two numbers





import java.io.*;




class Test {

public static void main(String[] args) throws IOException {

int n1,n2;

System.out.println("Enter first number:");

BufferedReader br1=new BufferedReader(new InputStreamReader (System.in));

n1=Integer.parseInt(br1.readLine());

System.out.println("Enter

Program to find fibonacci series in java


Java code to print Fibonacci series





import java.io.*;




class Test {



public static void main(String[] args) throws IOException {



int i=0,j=1,k=2,r,f;

System.out.println("Enter the range:");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

r=Integer.parseInt(br.readLine());

System.out.println("FIBONACCI SERIES: ");

Binary to decimal conversion in java


Java code to covert binary number to decimal number

import java.io.*;



class Test {

public static void main(String[] args) throws IOException {

long no,n=0l,j=1,rem,no1;

System.out.println("Enter the binary number");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

no=Long.parseLong(br.readLine());

no1=no;

Saturday, February 19, 2011

Perfect number program in java


Java code to check given number is perfect number or not

import java.io.*;



class Test {

public static void main(String[] args) throws IOException {

int n,i=1,sum=0;

System.out.println("Enter a number:-");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

n=Integer.parseInt(br.readLine());



while(i>0){

Armstrong number program in java


Java code to check give number is Armstrong number or not



import java.io.*;




class Test {

public static void main(String[] args) throws IOException {



int num,r,sum=0,temp;

System.out.println("Enter a number:-");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());

Strong number program in java


Java program to check given number is strong or not



import java.io.*;




class Test {

public static void main(String[] args) throws IOException {

int num,i,f,r,sum=0,temp;

System.out.println("Enter a number");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());

temp=num;



Prime number program in java


Java program to check whether given number is prime number or not





import java.io.*;




class Test {

public static void main(String[] args) throws IOException {

int num,i,count=0;

System.out.println("Enter a number");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());



Sum of digits of a number in java


Java code to add all digits of a numbers

import java.io.*;



class Test {

public static void main(String[] args) throws IOException {



int num,sum=0,r;

System.out.println("Enter a number:");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());



while(num!=0){

Java code to check whether give number is palindrome number or not



Palindrome program in java



import java.io.*;




class Test {



public static void main(String[] args) throws IOException {



int num,r,sum=0,temp;

System.out.println("Enter a number:");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());

temp=num;



LCM of two numbers in java



Java code to find the LCM i.e. least common factors of given two numbers




import java.io.*;




class Test {

public static void main(String[] args) throws IOException {



int n1,n2,x,y;

System.out.println("Enter first number:");

BufferedReader br1=new BufferedReader(new InputStreamReader (System.in));

n1=Integer.parseInt(br1.readLine());

Swapping two variables without using third variable in java



Java code to swap two numbers without using temporary variable




import java.io.*;




class Test {

public static void main(String[] args) throws IOException {



int a,b;

System.out.println("Enter first number:");

BufferedReader br1=new BufferedReader(new InputStreamReader (System.in));

a=Integer.parseInt(br1.readLine());

Floyd�s triangle parogram in java


Java code to print the Floyd�s triangle


import java.io.*;



class Test {

public static void main(String[] args) throws IOException {



int i,j,r,k=1;

System.out.println("Enter the range:");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

r=Integer.parseInt(br.readLine());

System.out.println("

Prime factors of a number in java



Java code to get the prime factors of give number


import java.io.*;



class Test {

public static void main(String[] args) throws IOException {

int num,i=1,j,k;

System.out.println("Enter the range:");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());



while(i<=num){

Multiplication tables program in java

Java code to print the multiplication table



import java.io.*;



class Test {

public static void main(String[] args) throws IOException {

int r,i,j,k;

System.out.println("Enter the range:");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

r=Integer.parseInt(br.readLine());



for(i=1;i<=r;i++){

Factorial program in java


Java code or program to find out the factorial of give number



import java.io.*;


class Test {

public static void main(String[] args) throws IOException {

int i=1,f=1,num;

System.out.println("Enter the number:");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());



Check leap year in java


Java code to check whether a given year in leap year or not



import java.io.*;




class Test {

public static void main(String[] args) throws IOException {

int year;

System.out.println("Enter the year");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

year=Integer.parseInt(br.readLine());

if(((year%4==0)&&(

Decimal to binary conversion in java


Java code to convert decimal number into binary number





import java.io.*;




class Test {

public static void main(String[] args) throws IOException {

long n,m,no=0l,a=1,rem;

System.out.println("Enter the decimal number");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

n=Integer.parseInt(br.readLine());

m=n;

while(n!=0){

Looping questions in java


Objective type mcq questions on loops in java and answers



(1)




public class Loop {

public static void main(String[] args) {

Integer a=012,b;

for(b=0;b<=a;b++);

System.out.print(b);

}

}



What will be the output of above java program?



(a)10

(b)11

(c)12

(d) Compiler error











Answer: (b)



(2)



public class Loop {

public static

switch case interview questions and answers in java


Objective questions on switch case in java and answers. Free online interview questions for beginners.




(1)





public class SwitchCase {

public static void main(String[] args) {

int a=12;

switch(a){

case 014:

System.out.print("I know java");

break;

case 12:

System.out.print("I don't know java");

Friday, February 18, 2011

if else program in java


If else conditional statement objective type questions in java


(1)



public class ControlStatement {

public static void main(String[] args) {

int a=25;



if(~a>25)

a++;

a+=a;



System.out.print(a);

}

}



What will be the output of above java program?



(a)-52

(b)50

(c)52

(d)Compiler error


Two dimensional array questions in java



faq 2 dimensional array questions and answers in java

(1)



public class ArrayDemo {

public static void main(String[] args) {

double arr[3];

arr[0]=2.1;

arr[1]=3.1;

arr[2]=4.1;

System.out.println(arr[1]+arr[2]);

}

}



What will be the output of above java program?



(a)7.2

(b) Any number greater than 7.2

(

Conditional operator questions in java


Questions on conditional operators in java and answers


(1)



public class Conditional {

public static void main(String[] args) {

int a=5;

Integer b=10;

int c=++a>++b?++a:++a+b;

System.out.print(c);

}

}



What will be the output when you will compile and run the above code?



(a)16

(b)17

(c)18

(d)19











Answer: (c)



(2)



public

Primitive data types questions in java


Data type mcq questions of java and answers

(1)



class Datatype {

public static void main(String[] args) {

byte num=(byte)130;

System.out.print(num);

}

}



What will be the output when you compile and run the above code?



(a)130

(b)3

(c)-126

(d)Compiler error











Answer: (c)



(2)



class Datatype {

public static void main(String[]

Basic java questions and answers


Basics core java questions and answers


(1) Which of the following option is not true about java programming language?



(a) Java is high level programming language.

(b) Java is a platform.

(c) javac is compiler.

(d) Byte code is executed by CPU.











Answer: (d)



(2) Which is a not characteristic of java programming language?



(a) Robust

(b)Procedural

(c) Distributed

(e

Java data type questions and answers


Java objective type data type questions and answers




(1)What will be the output of following java program?



class Datatype{

public static void main(String[] args){

byte num=(byte)130;

System.out.print(num);

}

}











Output: -126



(2)What will be the output of following java program?



class Datatype{

public static void main(String[] args){

Thursday, February 17, 2011

Conversion of binary number to decimal number using java programming language



import java.io.*;
class Test {


public static void main(String[] args) throws IOException {


long no,n=0l,j=1,rem,no1;

System.out.println("Enter the binary number");

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

no=Long.parseLong(br.readLine());
no1=no;
while(no!=0){
rem=no%10;
n=n+rem*j;
j=j*2;
no=no/10;
}

System.out.println("The value

Sunday, February 13, 2011

Core Java interview questions and answers


Basic Core java technical interview questions for freshers (J2EE) Collection




1. What is java run time environment?

2. How java is platform independent language?

3. What is difference between compiler and interpreter?

4. Java is secure language. Why?

5. Why main function in java is static?

6. What is abstract class and what is use of abstract class?

7. Why a class cannot be

Java question answer


java question papers answers for mca ,bca and diploma

(1)


public class Loop {


public static void main(String[] args){


int i=0;


boolean b=true;


for(i++;b;i++)


{


System.out.println(~i);


b^=true;


}


}


}


What will be output of above program?


(a)-2


(b)-3


(c)Infinite loop


(d)Compiler error


Java questions for freshers


Java written test questions and answers for freshers


(1)


public class SwitchCase {


public static void main(String[] args) {


int a=12;


switch(a){


case 014:


System.out.print("I know java");


break;


case 12:


System.out.print("I don't know java");


default:


System.out.print("I

Java question bank


Core java basics questions bank for quiz and answers

(1)


public class ArrayDemo {


public static void main(String[] args) {


int [] arr1,arr2;


arr1=new int[1];


arr2=new int[2];


arr1[0]='\n';


arr2[0]='a';


System.out.print(arr2[0]%arr1[0]);


}


}


What will be output of above program?


(a)6


(b)7


(c)0


(d)Compiler

Java questions and answers


Java multiple choice objective type questions for written test and answers

(1)


public class ArrayDemo {


public static void main(String[] args) {


long [][]arr=new long [2][];


arr[0]=new int[2];


arr[1]=new int[3];


arr[0][1]=015L;


System.out.println(arr[0][1]);


}


}


What will be output of above program?


(a)13


(b)15


(c)0

Saturday, February 12, 2011

Function parameters in c



Function parameters in c programming


1.Default parameter of function is void.





2.Only register storage class is allowed with function parameter.

#include




int devD(register int,register int);

int main(){




int temp;




temp=devD(5,25);




printf("%d",temp);




return 0;
}


int devD(int register x,int register y){




static int num;

return type of functions in c






return is keyword of c. When the control reaches to the return keyword it immediately terminates the execution of that function and transfer the control to the calling function.

Syntax of return statement:







Here expression is optional which has indicated by [ ].

Example:

#includeprintf

void dev();

int main(){

printf("one\n");

dev();

printf("two\n");

Function definition in c programming




Definition






Function is block or part of
program. When any program is very long or same code is repeating many times
then we try to cut the program in different parts (or blocks) so that whole
program became more understandable, easier to debug (error checking) and size
of code will be lesser.




Syntax of function in c
programming











Example of simple function







#include<

Tuesday, February 8, 2011

storage classes in c with examples


1. Introduction

2. auto

3. register

4. static

5. extern

C tutorial home.

C data types define in library files

Apart from this primary data type c library provides many very useful data types. Those data types are very necessary to write some program in c. Those data types with header files are:



(1) FILE (stdio.h)

(2) size_t (stdio.h)

(3) fpost_t (stdio.h)

(4) complex (math.h)

(5) ptrdiff_t

(6) wchar_t (stddef.h)

(7) time (dos.h)

(8) dostime_t (dos.h)

(9) date (dos.h)

(10)dosdate_t (dos.h)

(

User defined data types in c



reate data type VECTOR in c



Step 1: Write the following code in the file vector.h



//vector.h

typedef struct vect{

int i;

int j;

}VECTOR;



VECTOR add_vect(VECTOR x,VECTOR y){

VECTOR sum;

sum.i=x.i+y.i;

sum.j=x.j+y.j;

return sum;

}

void print(VECTOR z){

printf("%di+%dj",z.i,z.j);

}



Step 2: Now by including vector.h you can use VECTOR data type

extern keyword in c


Keyword extern is used for declaring extern variables in c. This modifier is used with all data types like int, float, double, array, pointer, structure, function etc.



Important points about extern keyword:



1. It is default storage class of all global variables as well all functions. For example, Analyze following two c code and its output:



(a)

#include

int i; //By

static variable in c


static keyword in c:



Keyword static is used for declaring static variables in c. This modifier is used with all data types like int, float, double, array, pointer, structure, function etc.



Important points about static keyword:



1. It is not default storage class of global variables. For example, analyze the following three programs and its output.



(a)



#include

int a;

register storage class in c




Register
storage class specifiers
in c with example



A register storage class is very similar to auto storage class except one most important property. All register variable in c stores in CPU not in the memory.



Important points about register storage class



(1)In following declaration:



register int a;



We are only requesting not forcing to compiler to store variable a in CPU.

auto storage class in c


auto:



Automatic variables or auto variables are default storage class of local variable. An auto variable cannot be declared globally. (Why?)




Properties of auto storage class.




(1) Default initial value of auto variable is garbage. For example:




#include

int main(){

int i;

auto char c;

float f;

printf("%d %c %f",i,c,f);

return 0;

}



Output:

Storage classes in c


In c there are four types of storage class. They are:

1. auto

2. register

3. static

4. extern


Storage class is modifier or qualifier of data types which decides:





1. In which area of memory a particular variable will be stored?


2. What is scope of variable?

3. What is visibility of variable?



Visibility of a variable in c:



Visibility means accessibility. Up to witch

Sunday, February 6, 2011

void in c















void data type in c



Linguistic meaning of void is nothing. Size
of void data type is meaningless question.



What
will be

enum in c


enum
is keyword of c with the help of enum we can create large numbers of constant
of type int, which are known as enum constants.


Syntax:




Note. [ ] indicate that they are
optional.

Example:

enum color{RED=1,GREEN=2,YELLOW=3}

c1, c2, c3;


Explanation of each term in syntax:


1.
: It is name of set
of all enum constants. Name of tag must be a valid identifier. This must be

float overflow in c

What will happen if we will go beyond
the range of float, double and long double data type?

Answer:



If
we will assign a value which is beyond the maximum value of that data type
compiler will assign +INF if number is positive and �INF if number is negative.
If we will assign a value witch is less than minimum value of that data type
then complier will assign a garbage value or zero.






Integer overflow in c
















3. Cyclic
nature of unsigned int:



Range
of unsigned int is 0 to 653535. If we will assign a value greater than 653535
then value of

char overflow in c
















1. Cyclic nature of unsigned char:



Consider following c program:

#include

void main(){

unsigned char c1=260;

Overflow in c


1. Overflow of char data type in c programming

2. Overflow of int data type in c programming

3. Overflow of long int data type in c programming

4. Overflow of float data type in c programming



5. Overflow of double data type in c programming




6. Overflow of enum data type in c programming



Introduction
List of data types
Primitive data types in c
Modifiers of data types in c
List of

Memory representation of float data type in c


(Both in Turbo c compiler and Linux gcc compiler)

Float
numbers are stored in exponential form i.e.



(Mantissa)*10^ (Exponent)



Here
* indicates multiplication and ^ indicates power.

In
memory only Mantissa and Exponent is stored not *, 10 and ^.

Total
size of float data type: 32 bit

Those
bits are used in following manner:

Exponent
bit: 8

Mantissa
bit: 24

Mantissa
is signed number,

float in c













Size
of float data type is four byte in all c compilers. It stores real number i.e.
floating point numbers. A floating point number cannot be

Memory representation of signed int





Total
size of unsigned int: 16 bit

Those eight bits are use as:

Data bit: 15

Signe bit: 1











Note: In c negative number is
stored in 2�s complement format.



Example:

(1)Memory
representation of:



signed int a=7; (In Turbo c
compiler)

signed short int a=7 (Both turbo c and
Linux gcc compiler)

Binary
equivalent of data 7 in 16 bit: 00000000 00000111

Data
bit:

Memory representation of int in c


Memory representation of unsigned int:

Total
size of unsigned int: 16 bit

Those eight bits are use as:

Data bit: 16











Example:

(1)Memory
representation of:



unsigned int a=7; (In Turbo c
compiler)

unsigned short int a=7 (Both
turbo c and Linux gcc compiler)



Binary
equivalent of data 7 in 16 bit: 00000000
00000111

Data
bit: 00000000 00000111

First
eight bit of data

int in c




What
is int or integer data type in c programming language with examples?


Size of int
data type depends upon which compiler we are using. Hence memory representation
also varies according to the compilers. Before explaining the memory
representation of int dada type I would like to one very important concept
endianess of operation system.



Endianess
of hardware:


There are
two types

short int in c programming langauge

Data types in c language: short integer


Size
of short is two byte in the 16 bit compilers like turbo c++, Borland c++ as
well as 32 bit compilers like Linux gcc compiler. In Turbo c compiler size of
both short int and int is two byte. Hence there is not so importance of short
int Turbo c compiler but in Linux gcc compiler size of short int is two byte
while size of int is four byte. Since

Memory representation of signed char in c


(2)Memory representation of: signed char a=-7;



Binary
equivalent of data 7 in eight bit: 00000111

Binary
equivalent of data -7 will be its 2�s complement:

1�s
complements of 0000 0111 is 1111 1000

2�s
complement will be:











Binary
equivalent of data -7 in eight bit: 1111 1001

Data
bit: 1111001 (Take first seven bit form right side)

Sign
bit: 1 (Take
leftmost one bit)



Memory representation of char in c


Example:



Memory representation of: signed char a=7;



Binary
equivalent of data 7 in eight bit: 00000111

Data
bit: 0000111 (Take first seven bit form right side)

Sign
bit: 0 (Take leftmost
one bit)

In
memory:








Introduction
List of data types
Primitive data types in c
Modifiers of data types in c
List of modifiers in c
Default modifiers of data types in c
Default data of

char in c
















char
data type in c



It is one
byte data type both in Turbo c compiler and Linux gcc compiler.



Memory
representation of

Saturday, February 5, 2011

Fundamental data types in c


It is also called as Primitive data type.

1. char

2. int

3. float

4. double

5. void


Introduction
List of data types
Primitive data types in c
Modifiers of data types in c
List of modifiers in c
Default modifiers of data types in c
Default data of modifiers in c
Rules of using modifiers in c
Possibles modifiers of given data types in c
Size modifier in c
Size of data types in c
Sign

volatile modifier in c


All variable in c are by default not volatile. With
help of modifier volatile which is keyword of c language you can make any
variable as volatile variable.

Properties of volatile variable:



1. A volatile variable can be changed by the
background routine of preprocessor. This background routine may be interrupt
signals by microprocessor, threads, real times clocks etc.



2. In simple word we

const modifier in c


Explanation of const modifier in c programming language
by examples, questions and answers:


In c all variables are by default not constant. Hence, you can modify the value
of variable by program. You can convert any variable as a constant variable by
using modifier const which is keyword of c language.



Properties of
constant variable:





1. You can
assign the value to the constant

C data types limits


How
to remember size of data type in c?



If you have
memorized the size of data type in all types c compiler then there is not any
problem. If you cannot memorized then it is also not a problem because every c compiler
provide one header file
which contain some micro constants for size of integral data type which is easy
to memorize. Those micro constants are:





IN

Range of data types in c




Following table illustrate the range or maximum or minimum value of data types in
TURBO C++ and Borland c++ compilers.









Note: In the above table range of
float, double and long double has written only for positive numbers. But this
range is also true for negative numbers i.e. for range of float is -3.4*10^38
to -3.4*10^ (-38) and so on.



Interview
Question:
Why range of signed char

Modifiers in c language


2.
SIGN MODIFER:



These
modifiers are responsible for to make data type signed or unsigned. Both signed
and unsigned modifiers affect the range of a data type. In c char all primitive
data type except void are by default signed. If you will write:

signed char c;

signed short int si;

signed int i;

signed long int li;



Compiler will not show any error or warning message
but it

Size of data types in c



Size of data types in c
programming language turbo C and GCC compilers



Size of data types in the 16 bit compilers, like
TURBO c++ 3.0, Borland c++ etc:





Size of data types in the 32 bit compilers. Example:
LINUX gcc compiler, Turbo c 4.5 etc:






Introduction
List of data types
Primitive data types in c
Modifiers of data types in c
List of modifiers in c
Default modifiers of data types

C programming modifiers


Importance
of all eight group of modifier in c:



1.
SIZE MODIFIERS:

Only two
modifiers short and long can affect the size of any data type in c. size of
primitive data type in c depends upon the word length of the microprocessor. In
general we can say size of int is word length of microprocessor.



Introduction
List of data types
Primitive data types in c
Modifiers of data types in c

Modifiers of variable in c


Possible
modifiers with given data type in c



We cannot use all modifiers with each data types in
c. Following table represents permitted or meaningful modifiers which can be
used with a particular data type.




Some
important points regarding above table:



1. In case of array and pointer, size and sign
modifier depends upon which data type you are using in the declaration of array
and

Modifiers in c




Explanation of modifiers in
c programming language by examples and questions



Rules for using modifier in c





Rule 1: We cannot use
two modifiers of same groups in any particular data type of c.



For example,
following declaration of c are illegal:





short long int i;



static auto char c;



signed unsigned int array[5];



pascal cdecl display();





Following are
valid

Default data type in c


Default data type is opposite of default modifier as
you read in the above topic. In case of only SIZE, SIGN, STORAGE CLASS,
CONSTANT, and VOLATILE modifier compile automatically assumes int as a default
data type. For example:



(1)

long a=25;

It is equivalent to: long int a=25;

(2)

signed a=25;

It is equivalent to: signed int a=25;

(3)

register a=25;

It is equivalent to: unsigned

Default modifier or Qualifiers of variables in c programming


Modifier or Qualifiers of variables and data types in c programming


If you will
not write any modifiers of a particular group then c compiler will take default
modifier of that group. Default modifier of each group has written in the
following table:




Modifiers and Qualifiers of data types in c




1. Default modifier of storage class is auto when we
declared the variable inside any

List of modifiers in c






In the above table modifier ending with * indicates
they are not keyword of c language. These modifiers are called as nothing
modifier since there is not any special keyword in which represents those
modifiers. If you will not write any thing it then compiler will understand you
are writing nothing modifier of those groups.



Meaning of
following word in the above table:



nothing: It is

C data type modifiers




Modifiers in c
programming language of data types



There are some keywords in c which modify the
meaning the meaning of above mentioned basic data type in c. On the basis of
properties of modifier we can categories the modifier in following eight
groups.



1. Size modifier

2. Signed modifier

3. Constant modifier

4. Volatile modifier

5. Storage class

6. Pointer modifier

7. Function

Primitive data types in c


Primitive or most fundamental data type in c can be categorized
in three groups on the basis of its application:



1. Integral type number: char ,
int

2. Real type number: float ,
double

3. Void or nothing type: void




Introduction
List of data types
Primitive data types in c
Modifiers of data types in c
List of modifiers in c
Default modifiers of data types in c
Default data of modifiers

List of data type in c




A complete picture of all c data types has been represented
by following figure.

















Note: Apart from these basic data type there are few
other data types which have been defined inside header files which will be
discussed later.




Introduction
List of data types
Primitive data types in c
Modifiers of data types in c
List of modifiers in c
Default modifiers of data types in c

Introducing c data type




Every programming language
deals with some data. For example to print any message it requires charterer or
string type of data. To solve any mathematic expression it requires integral as
well as real number (floating type) of data. C is very rich in data type. We
can broadly divide all data type in c in three categories:



1. Primitive or fundamental
data type

2. Derived data type

3. User

Data types in c language

Data types in c

1. Introduction

2. List of data types

3. Primitive data types in c

4. Modifiers of data types in c

5. List of modifiers in c

6. Default modifiers of data types in c

7. Default data of modifiers in c

8. Rules of using modifiers in c

9. Possibles modifiers of given data types in c

10. Size modifier in c

11. Size of data types in c

12. Sign modifier in c

13. Range of

Data segment in c




All the segments are used
for specific purpose. Like segment number 15 is used for ROM, segment number 14
is used for BIOS etc.











We will discuss about how to access text video
memory, graphics video memory in the pointer and union chapters of 255 bits
color graphics programming.


Segment number eight has special name which is known
as data segment. This segment has been divided

What is offset address


What is
offset address?

Offset address and segment
number in c programming language






Each segment has divided into two parts.









1. Segment no (4 bit)




2. Offset address (16 bit)












So, in the other words we can say memory address of
any variable in c has two parts segment number and offset address.



In turbo c 3.0 a particular segment number offset
address varies from

Memory segment | Segment address


Memory
segmentation in 8086 microprocessor : Segmented
memory






Resident memory of RAM of
size 1MB has divided into 16
equal parts. These parts is called segment. Each
segment
has size is 64 KB.



16 * 64 KB = 1 MB







This process of division is
known as segmentation.









Note: In turbo c 3.0 physical addresses of any
variables




are stored in the 20 bits. But we have not any

Wednesday, February 2, 2011

Physical address of a computer


Logical
address and physical address: How to find

or get a physical address of a RAM


physical address of computer or operating system

All the c variables are stored in the residence memory.

In turbo C 3.0, 20 bits address of the memory cell is
known as physical address or real address. In 20 bits,
we can represent address from 0x00000 to 0xFFFFF. That
is all c variables must have

what is resident memory




What is resident memory of a computer?



RAM has divided into two parts:

(1) Extended memory (useless)

(2) Residence memory




























































In Turbo C 3.0 compiler size of residence memory is 1MB.



resident memory:



When any program is executed it is stored in the
residence memory. For turbo c 3.0, it has 1MB residence

What is the ram of a computer?




What is the
ram memory: Memory cell in computer





Entire RAM has divided in numbers of equal parts, which are

known as memory cells. Following diagram represents the 256

MB RAM.









Each cell can store one-byte data. Data are stored in the
binary number system. That is a character data reserves one
memory cell while floating data reserves four memory cells.



Each memory cell

Difference between .com program and .exe program in c programming language



Both .com and .exe program are executable program
but .com program execute faster than .exe program. All drivers are .com
program. .com file has higher preference than .exe
For example:
Open the command prompt in window OS. (Type CMD in Run)
In the command prompt type notepad and press enter key you will get the notepad. Since it executes notepad.exe

Repeat the same task but now first create

Difference between TSR and TSO program


Difference between TSR and TSO program


TSO means terminate but stay outside.
It is that program, which release the main memory after the execution of the
program. Example ms paint, notepad, turbo c compilers etc.



TSR means terminate but stay
residence .It is those program, which after the execution of the program does not
release the RAM (main memory).e.g. antivirus.


List the five c

What will be address range which can be represented in 20 bit?





Binary

Hexadecimal


Min possible

0000 0000 0000 0000 0000

00000


Max possible

1111 1111 1111 1111 1111

FFFFF






In c any hexadecimal number start with 0x 0r 0X So, address range will be 0x00000 to 0xFFFFF. So in turbo C 3.0 memory address of all variables must be within 0x00000 to oxFFFFF.



It is 1MB memory range.



Note.

2^10 = 1KB

2^20 = 1MB

Hexadecimal representation in c


In
hexadecimal number system we use 16 different digits so its base is 16. List of
all hexadecimal digits:








Hexadecimal digit


Decimal equivalent


Binary equivalent




0


0


0000




1


1


0001




2


2


0010




3


3


0011




4


4


0100




5


5


0101




6


6


0110




7


7


0111




8


8


1000

Turbo c compiler




Turbo c is an IDE of c programming language created by Borland. Turbo C 3.0
is based on MS DOS operation
system. It is one of the most popular c compilers. It uses 8086 microprocessor which is 16
bit microprocessor. It has 20 address buses and 16 data bus. Its word length is
two byte.

Size of data types in Turbo C 3.0:






Data type


Size




short int


2




int


2


C compiler


There are various c compilers are variables. Some of these are:






S.N.


Name


Microprocessor


OS




1


Turbo c 3.0


8086


MS DOS




2


ANSIC C


80386


LINUX




3


Borland C 4.0


80386


WINDOW




4


Microsoft C


8086


MS DOS




5


Visual C++


80386


WINDOW





Note: 8086 is 16 bit microprocessor while 80386 is 32

Memory mapping in c


Basic knowledge before staring c programming language. To become best c programmer you must have knowledge about memory mapping.



1. List the five c compilers?

2. Describe turbo c compiler?

3. What is hexadecimal number system?

4. What will be address range which can be represented in 20 bit?

5. What is difference between TSR and TSO program?

6. What is difference between .com program and