×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

small notes on pointers and strings

small notes on pointers and strings

small notes on pointers and strings

(OP)
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;
    
    
}
 

RE: small notes on pointers and strings

(OP)
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
 

RE: small notes on pointers and strings

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", a[3], 3[a]);
}
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
 

RE: small notes on pointers and strings

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close