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

This is a discussion on this is a simple p[rogram that i hope has a simple answer? within the C Programming forums, part of the General Programming Boards category; Hi! I am suppose to write a code that uses this char declaration and its suppose to print out values ...

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

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

    Hi!
    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?

    Code:
    #include<stdio.h>
    
    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
    Posts
    6,231
    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.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        char    a, *p;
    
        printf("sizeof(a) : %d\n", sizeof(a));
        printf("sizeof(p) : %d\n", sizeof(p));
    
        return(0);
    }
    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, 02:57 PM
  3. simple answer? test your IQ
    By Fountain in forum A Brief History of Cprogramming.com
    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, 12:12 PM
  5. Is there a simple answer?
    By Jamazon in forum C++ Programming
    Replies: 2
    Last Post: 12-08-2001, 03:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21