Showing posts with label Data types. Show all posts
Showing posts with label Data types. Show all posts
Friday, February 3, 2012
Data type questions in c
Data types interview questions and
answers with explanation
Note: As you know size of data types is compiler dependent in c. Answer of all question is based upon that compilers whose word size is two byte. Just to know you, size of data type in 2 bytes compilers is as follow:
char : 1 byte
int :
Sunday, February 20, 2011
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
Friday, February 18, 2011
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[]
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){
Tuesday, February 8, 2011
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)
(
(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
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.
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.
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
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
Subscribe to:
Posts (Atom)