Sunday, June 05, 2005

Miscellaneous C Questions

1. How to find if a stack is progressing in forward or backward
direction using a C program?
//This code relies on the fundamental idea that function calls uses stack.

#include<stdio.h>
int* globalvar;
void myfunc(void);

int main()
{
int i,*x=&i;
myfunc();
if((globalvar-x)>0)
printf("stack progression forward");
else
printf("Stack progression backward");
}

void myfunc(void)
{
int j;
globalvar=&j;
return;
}

2. How exactly are \c and \v used in C. when i give them in a printf
statement, strange characters are printed.

according to K &R, any non standard (ie., the one's for which \(char) form is not defined, the result of printing such a thing is undefined!)
for \c ->test.c:6:16: warning: unknown escape sequence '\c'
for \v -> it prints this character - ♂ !! i read here \v stands for vertical tab and is not working (in windows gcc).

3.typedef struct{
char *;
nodeptr next; //this should be nodeptr* next; (updated from algo-geeks)
} * nodeptr;
what does nodeptr stand for?

the purpose of typedef is to provide a compile time new name.
typedef int* integer_pointer; (will allow u to write integer_pointer a; , "a" now is a pointer to an integer. )
you can understand this as:
typedef (structureinfo)* newname;
this causes nodeptr to be a pointer to the anonymous structure defined above.
Although technically right, this declaration is useless!, since the structure is anonymous.
correct me if i am wrong somewhere.
-வருண்
சௌ . வருண் அங்கு ஜீஅஞ்சல் . வணிகம்
;-)

5 comments:

srid said...

See http://groups-beta.google.com/group/algogeeks/browse_thread/thread/9d0d2082964b1a4b/29ac455cf46623f2#29ac455cf46623f2

Santhosh S R said...

Take a look at the index entry for 'recursion'. It lists all the pages and the page no. for the index entry also. No other word has this. This explains the concept of recursion better than the examples! ;)

Ranjhith said...

> சௌ . வருண் அங்கு ஜீஅஞ்சல் . வணிகம்

Gmail and com are proper nouns and not verbs. So please do not translate them.

When I write Varun in English, should I have to translate it as RainGod? >:O) Just a parody.

Varun Soundararajan said...

hahah, that translation was just for fun, the ;-) at the end was a message to say that it was for fun, not to go by grammar.
Bye
Varun

Anonymous said...

good question da maapi

Search this site

Google