good c fundu book and simple programs

Status
Not open for further replies.

adithya_spec

Broken In
hi guys
1>how to write a c program so that the whole program shud print in the output and then the reqiured statements without using printf().
2>how to swap the values of two integer without using temporary variables as well as any arithmetic operations
3>i wrote a program as below
void main()
{
char c[30]="c is tough";
char *p="no";
printf("%d",((sizeof(c)-sizeof(p)));
}
and i got the output as
8
why i expected it to be
-1 (since c is the 0th element and its size is 1 and p is a pionter and its size is 2)
4>another program
void main()
{
printf("%d",printf("hello"));
}
the output of this will be
hello5
why is that 5 of course hello has 5 letters but why shud it come?

is there any good book which has these type of questions
other than "test ur c skills"
if there please tell me.
 

sakumar79

Technomancer
4. See your printf statement carefully - printf("%d",printf("hello")); You have nested printf statement... The inner printf statement prints first giving hello. It returns 5 as the number of characters printed. Then the outer printf takes the 5 as the parameter to be printed...

Arun
 

casanova

The Frozen Nova
swapping witout a temporary variable

no1=no1+no2
no2=no1-no2
no1=no1-no2

and i didn't understand ur first question. If u need a substitute, you cud use putchar() or putch() and for strings u can use puts. I personally prefer putchar() and putch() in big projects as it gives me better control.
 
Status
Not open for further replies.
Top Bottom