Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
The %zu marker should return value when You use sizeof() function. In a console application there is a message "The chapters array uses zu bytes of memory." It should return number of bytes used by these two stings, not this "zu".

C#
#include <stdafx.h>
#include <stdio.h>
#include <stdlib.h>
#define CHAPTER0 "Introduction"
#define CHAPTER1 "Getting started with C"
#define CHAPTER2 "Introduction to Data Types"
#define CHAPTER3 "Working with Numbers"
#define CHAPTER4 "Control Structures"

int main (void) {
    char chapters[5][27] = {CHAPTER0, CHAPTER1, CHAPTER2, CHAPTER3, CHAPTER4};
    char *chapters_ptr[5] = {CHAPTER0, CHAPTER1, CHAPTER2, CHAPTER3, CHAPTER4};
    printf ("The chapters array uses %zu bytes of memory.\n", sizeof(chapters));
    printf ("The chapters_ptr array uses %zu bytes of memory.\n", sizeof(chapters_ptr));
    getchar();
    return 0;
}
Posted

1 solution

%zu is not a valid modifier for printf()(the z is not a modifier at all):
http://www.cplusplus.com/reference/clibrary/cstdio/printf/[^]

use this instead and it should work just fine:
printf ("The chapters array uses %u bytes of memory.\n", sizeof(chapters));
 
Share this answer
 
v2
Comments
Member 641034 24-Jun-11 14:13pm    
Yes, than you, I read it in the book. Must be a print error in the book I am using.
Albert Holguin 24-Jun-11 14:21pm    
Could be, cheers! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900