I'm doing a college assignment in C. We have to write a simple programme that just creates different data types (ints, longs, doubles) and prints them out and their size using the sizeof() function. This is the code I have written for the function that creates an int:
void createInt(){
int i = 3;
printf(int i);
printf(sizeof(int i));
}
It's giving the following errors: For "printf(int i);" it's giving: warning C4047: 'function': 'const char *const ' differs in levels of indirection from 'int' For "printf(sizeof(int i));" it's giving: warning C4024: 'printf': different types for formal and actual parameter 1
Any help would be greatly appreciated. I'm completely new to C. Have never used it before. Thanks!
What the error means is that you're passing the wrong type of parameter to the function printf. It was declared to take a const char *
as its first parameter. You're passing it an int
then a size_t
.
When printf
takes only one parameter, that parameter must be a string. But if you want to print the content of the integer i
use printf("%d", i)
or the value of sizeof(i)
which is of the type size_t
use it like this : printf("%zu%, sizeof(i))
printf
needs a string as its first parameter. What you mean to do is
printf("%i\n", i);
printf("%zu\n", sizeof i);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.