The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Program tracking..
Discuss Program tracking.. in the C Programming forum on Dev Shed. Program tracking.. C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 28th, 2012, 11:37 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Time spent in forums: 33 m 41 sec
Reputation Power: 0
|
|
|
Program tracking..
I am unable 2 understand the following programs and their output.. can u pls help..
1.
main()
{
float me=1.1;
double you=1.1;
if (me==you)
printf("I hate C");
else
printf("I love C");
}
2.
main()
{
char word[25];
printf("word\n");
scanf("%[A...I]c",word);
printf("input");
scanf("%[^'0']c",word);
printf("over");
getch();
}
3.
main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0')
++*p++;
printf("%s%s",p,p1);
}
4.
main()
{
int a[]={1,4,3,5,7};
int i=2;
printf("%d",a[i][a]);
getch();
}
|

December 28th, 2012, 03:05 PM
|
 |
Contributing User
|
|
|
|
|
These programs are useful for obfuscation contests. Don't write like this. Take #4.
int a[]={1,4,3,5,7};
int i=2;
printf("%d",a[i][a]);
Per my understanding, c evaluates pointer[integer] as
*(pointer+integer)
Addition commutes, (a+b) == (b+a)
*(integer+pointer)
hence you can write
integer[pointer]
But please don't, your fellow programmers aren't likely to think that way.
a[i][a]
a[i] is an integer, giving
integer[a]
a is a pointer
a[i][a] looks valid to me.
#1, I'd have to build and run, otherwise I'd have to spend maybe hours studying IEEE floating point. The key is to investigate number representations and what happens as the compiler casts through successive types. Again, that's part of the c standard.
#3, study precedence and left-to-right versus right-to-left order of operation. Don't write code like that!
#2, study the man pages for printf.
__________________
[code] Code tags[/code] are essential for python code!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|