Friday, October 16, 2009

SOME C DEFINITION

1.POINTER VALUE : It is the variable address the pointer contains and the VALUE THE POINTER to is the content of that variable whose address stored in the pointer .The "&" operator can be remembered as ADDRESS OF and the indirection operator "*" can be remembered as VALUE AT ADDRESS .We use "%u" format for printing Address values as Memory address are Unsigned Integers.


Sunday, September 20, 2009

FILE IN C

01.WHAT IS FILE IN C?
Ans: A file is a place on the disk where a group of related data stored in. the keyword "FILE" is a data type that is defined in the I/O libary . The FILE type pointer contains all the infomation about the FILE is subsequently used as a communication link between the system and the program.

OPENING THE FILE: when working witha stream-orinted data file , the first step establish a "buffer area" ,where information is temporarily stored while being transferred between the computer's memory and data file .This buffer area allows information to be read from or written to the data file more rapidly than would otherwise be possible .
The buffer area is establish by writing
FILE *fp1 ;

Tuesday, September 8, 2009

CONSTRUCTOR (JAVA)

01.WHAT IS COSTRUCTOR IN JAVA?
ans. in java constructor initialize an object.In consturctor class name and constrructor name must be same .It has no return type even void .

CONSTRUCTOR are two type in java.i)default , ii)parameterized.

EXAMPLE:
class A{

A(){ // DEFAULT CONSTRUCTOR......
}

A(1,2,3){ //PARAMETERIZED CONSTRUCTOR...
}
}

N.B:IN JAVA COPY CONSTRUCTOR NOT SUPPORTED i,e.IN JAVA COPY CONSTRUCTOR NOTHING BUT A GENERAL CONSTRUCTOR.......

Wednesday, September 2, 2009

CALL BY REFENCE.

swapping the two no.

void main()
{
void myudf(int * , int *); //function declaration ....ansi or modern style.....
int nx , ny ;
int *px , *py ;
px = &nx ;
py = &ny ;

printf("ENTER TWO NO.S ") ;
scanf("%d %d" , px ,py);

myudf(px , py); // funtion calling.....................

printf("BACK TO MAIN: THE FISRT NO IS[%d] AT ADDR [u] SECOND IS :[%d] AT ADDR [%u] " , *px , px , *py , py );

getch();
}
//............END OF MAIN............................

void myudf( int *pnx , int *pny)
{
int z ;

z = *pnx ;
*pnx = *pny ;
*pny = z ;

printf("AT UDF : NOW THE FIRST NO. IS:[%d]AT ADDR [%u] THE SECOND NO.[%d] AT ADDR [%u] " ,*pnx , pnx , *pny , pny );

getch();
}

Monday, August 24, 2009

program langauge

program langauge are three types.

i.procedural langauge(C )
ii.object oriented programing(java , SMALL TALK )
iii. object based programing( VB)

in three types VB is not case sensitive langauge..

Sunday, August 2, 2009

block diagram of cpu


c programing

1. main()

{

char string[]="Hello World";

display(string);

}

void display(char *string)

{

printf("%s",string);

}

Answer:

Compiler Error : Type mismatch in redeclaration of function display

Explanation :

In third line, when the function display is encountered, the compiler doesn't know anything about the function display. It assumes the arguments and return types to be integers, (which is the default type). When it sees the actual function display, the arguments and type contradicts with what it has assumed previously. Hence a compile time error occurs.

2. main()

{

int c=- -2;

printf("c=%d",c);

}

Answer:

c=2;

Explanation:

Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus= plus.

Note:

However you cannot give like --2. Because -- operator can only be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.

3. #define int char

main()

{

int i=65;

printf("sizeof(i)=%d",sizeof(i));

}

Answer:

sizeof(i)=1

Explanation:

Since the #define replaces the string int by the macro char

4. main()

{

int i=10;

i=!i>14;

Printf ("i=%d",i);

}

Answer:

i=0

Explanation:

In the expression !i>14 , NOT (!) operator has more precedence than ‘ >’ symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).

5. #include

main()

{

char s[]={'a','b','c','\n','c','\0'};

char *p,*str,*str1;

p=&s[3];

str=p;

str1=s;

printf("%d",++*p + ++*str1-32);

}

Answer:

77

Explanation:

p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11. The value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98.

Now performing (11 + 98 – 32), we get 77("M");

So we get the output 77 :: "M" (Ascii is 77).

6. #include

main()

{

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };

int *p,*q;

p=&a[2][2][2];

*q=***a;

printf("%d----%d",*p,*q);

}

Answer:

SomeGarbageValue---1

Explanation:

p=&a[2][2][2] you declare only two 2D arrays, but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. Now q is pointing to starting address of a. If you print *q, it will print first element of 3D array.

7. #include

main()

{

struct xx

{

int x=3;

char name[]="hello";

};

struct xx *s;

printf("%d",s->x);

printf("%s",s->name);

}

Answer:

Compiler Error

Explanation:

You should not initialize variables in declaration

8. #include

main()

{

struct xx

{

int x;

struct yy

{

char s;

struct xx *p;

};

struct yy *q;

};

}

Answer:

Compiler Error

Explanation:

The structure yy is nested within structure xx. Hence, the elements are of yy are to be accessed through the instance of structure xx, which needs an instance of yy to be known. If the instance is created after defining the structure the compiler will not know about the instance relative to xx. Hence for nested structure yy you have to declare member.

9. main()

{

printf("\nab");

printf("\bsi");

printf("\rha");

}

Answer:

hai

Explanation:

\n - newline

\b - backspace

\r - linefeed

10. main()

{

int i=5;

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

}

Answer:

45545

Explanation:

The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result.