Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 15-11-2005, 09:05 AM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Oct 2005
Location: bagalore
Posts: 14
Default good c fundu book and simple programs


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.
adithya_spec is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 15-11-2005, 10:09 AM   #2 (permalink)
Wise Old Owl
 
desertwind's Avatar
 
Join Date: Nov 2004
Location: Hyderabad
Posts: 1,096
Default

2. a ^= b ^= a ^= b
3. size of(c) =10
size of (p)=2
__________________
Sometime you'll think you understand everything

...Then you'll regain consciousness
desertwind is offline  
Old 16-11-2005, 07:22 AM   #3 (permalink)
Human Spambot
 
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
Default

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
sakumar79 is offline  
Old 20-11-2005, 05:31 PM   #4 (permalink)
The Frozen Nova
 
casanova's Avatar
 
Join Date: Sep 2004
Location: Trespasser in Virtual Land
Posts: 1,641
Default

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.
__________________
I dream of a better tomorrow... where chickens can cross roads and not have their motives questioned.

www.nerdweed.blogspot.com
casanova is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by clmlbx
- by gforz
- by Who

Advertisement




All times are GMT +5.5. The time now is 04:52 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2