Thread: this is a simple p[rogram that i hope has a simple answer?

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002

    Question this is a simple p[rogram that i hope has a simple answer?

    I am suppose to write a code that uses this char declaration and its suppose to print out values that can tell me how many bytes are alloted for each variables?

    My answer is 1 bytes. Is that correct since there are 4 bits to one byte or is it 8 bits?

    int main()
    	char  a, b, c, *p, *q, *r;
    		printf("%p\n%p\n%p\n", a, b, c);
    		printf("%p\n%p\n%p\n", *p, *q, *r);
    		return 0;

    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    It's 8 bits to a byte.

    >printf("%p\n%p\n%p\n", a, b, c);
    Isn't printing the size of the variables. To do that you need the sizeof operator.
    #include <stdio.h>
    int main(void)
        char    a, *p;
        printf("sizeof(a) : %d\n", sizeof(a));
        printf("sizeof(p) : %d\n", sizeof(p));
    Note that pointers take up more than 1 char (on my system they take up 4). This number represents the size of the pointer itself, not the size of the data that the pointer is pointing to.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. probably a simple answer
    By sweetly in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2003, 01:43 PM
  2. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  3. simple answer? test your IQ
    By Fountain in forum A Brief History of
    Replies: 12
    Last Post: 07-11-2002, 04:32 PM
  4. code help :)
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 02-28-2002, 01:12 PM
  5. Is there a simple answer?
    By Jamazon in forum C++ Programming
    Replies: 2
    Last Post: 12-08-2001, 04:03 PM