Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

small notes on pointers and strings

Status
Not open for further replies.

manichandra

Technical User
Feb 6, 2012
19
US
int main()
{
char *p="MANI";
char *q;

printf("%c %c %c %c\n",'M','A','N','I');
printf("%d %d %d %d\n",'M','A','N','I');

printf("%d %d %d %d %d %d %d\n", *p,*(p+1),*p+1,*(p+2),*p+2,*(p+3),*p+3);
printf("%c %c %c %c %c %c %c\n", *p,*(p+1),*p+1,*(p+2),*p+2,*(p+3),*p+3);

printf("%s %s %s %s\n", p,(p+1),(p+2),(p+3));
printf("%s %s %s %s\n", p,p+1,p+2,p+3);

printf("%d %d %d %d\n", p,(p+1),(p+2),(p+3));
printf("%d %d %d %d\n", p,p+1,p+2,p+3);

q=p;

printf("%d\n",q);
printf("%s\n",q);

q=p+1;

printf("%d\n",q);
printf("%s\n",q);

return 0;


}
 
output:


M A N I
77 65 78 73
77 65 78 78 79 73 80
M A N N O I P
MANI ANI NI I
MANI ANI NI I
3844 3845 3846 3847
3844 3845 3846 3847
3844
MANI
3845
ANI
 
This one blows my mind...
Code:
#include <stdio.h>

main()
{
        float a[4] = {1.1, 2.2, 3.3, 4.4};

        printf("\n%f - %f\n", [b]a[3][/b], [b]3[a][/b]);
}
It compiles and runs perfectly on every C compiler I've tried. Seems it would be a cool way to obsfucate some code if you wanted to.

[bigsmile]
 
If you wish to print the value of a pointer, use %p. On some compilers (eg gcc), using %d or %x to print a pointer will only result in a compilation error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top