

Makes Pointer From Integer Without a Cast: Fix It Now!
- Recent Posts

- Typeerror: ‘Int’ Object Is Not Callable: A Set of Solutions - November 24, 2023
- 422 error: A Guide Explaining the Reasons and Solutions - November 24, 2023
- HTTP Error 503. The Service Is Unavailable. What Went Wrong? - November 24, 2023

Our research team has ensured that this will be your best resource on these error messages, and you won’t have to read another article about it again. With that said, launch your code that’s showing the error messages, and let’s fix it for you.
JUMP TO TOPIC
– You Assigned an Integer to a Pointer
– you want to convert an integer to a pointer, – you passed a variable name to the “printf()” function, – you used “struct _io_file” in a wrong way, – you copied a string to an invalid location, – you’re setting a pointer to a different type, – use equal data types during assignment, – ensure the pointer and integer have the same sizes, – pass a “format string” to the “printf()” function, – use a function that returns a pointer to “struct _io_file”, – copy the string to character array or character pointer, – assign pointers of compatible types, why your code made a pointer from an integer without a cast.
Your code made a pointer from an integer without a cast because you assigned an integer to a pointer or you want to convert an integer to a pointer. Other causes include the passing of a variable name to the “printf()” function and using “struct _io_file in the wrong way.
Finally, the following are also possible causes:
- You copied a string to an invalid location
- You’re setting a pointer to a different type
If you assign an integer to a pointer, it will lead to the “ assignment makes pointer from integer without a cast c programming ” error. For example, in the following, the “num_array” variable is an unsigned integer type while “tmp_array” is a pointer.
Later, an error will occur when the “for” loop tries to copy the values of the “num_array” to the “tmp_array” pointer using a variable assignment.

For example, in the following, the “theta” variable is an integer while “ptr_theta” is a pointer. Both have different sizes, and you can’t convert the integer to a pointer.
If you pass a variable name to the “printf()” function, that’s when the compiler will throw the “ passing argument 1 of ‘printf’ makes pointer from integer without a cast ” error.
For example, in the following, “num_val” is an integer variable, and the code is trying to print it using the “printf()” function.
When you assign an integer to a pointer of “struct _io_file”, that’s when you’ll get the “ assignment to file aka struct _io_file from int makes pointer from integer without a cast ” error. For example, in the following code, “FILE” is a “typedef” for “struct _io_file”. This makes it a pointer to “struct _io_file”.
Later, the code assigned it to the integer “alpha,” and this will lead to an error stated below:

Now, in the following, the code is trying to copy a string (“source”) into an integer (“destination”), and this leads to an error because it’s not a valid operation:
When your code sets a pointer to a different type, your compiler will show the “ incompatible pointer type ” error. In the following code, “pacifier” is an integer pointer, while “qwerty” is a character pointer.
Both are incompatible, and your C compiler will not allow this or anything similar in your code.

How To Stop a Pointer Creation From an Integer Without a Cast
You can stop a pointer creation from an integer without a cast if you use equal data types during the assignment or ensure the integer and pointer have the same sizes. What’s more, you can pass a “format string” to “printf()” and use a function that returns a pointer to “struct _io_file”.
- Copy the string to a character array or character pointer
- Assign pointers of compatible types
During a variable assignment, use variables of equal data types. In our first example, we assigned a pointer (uint8_t *tmp_array) to an unsigned integer (uint8_t num_array) and it led to a compile-time error.
Now, the following is the revised code, and we’ve changed “tmp_array” to a real array. This will prevent the “ gcc warning: assignment makes pointer from integer without a cast ” error during compilation.

Now, the fix is to use “intptr_t” from the “stdint.h” header file because it guarantees that the pointer and integer will have the same sizes. We’ve used it in the following code, and you can compile it without an error.
To fix the “pointer to integer without a cast” in the “printf()” function, pass a “format string” as its first argument. How you write the “format string” depends on the variable that you’ll print. In the following updated code, “num_val” is an integer, so the “format string” is “%d”.
When you’re using “FILE” from the “stdlib.h” header file, you can prevent any “pointer from integer” error if you use a function that returns a pointer to “struct _io_file”.
An example of such a function is “fopen()” which allows you to open a file in C programming. Now, the following is a rewrite of the code that causes the pointer error in “struct _io_file”. This time, we use “fopen()” as a pointer to “FILE”.

Now, in the following code, we’ve changed “destination” from an integer to a “character array”. This means “strcpy()” can copy a string into this array without an error.
Meanwhile, the following is another version that turns the “destination” into a “character pointer”. With this, you’ll need to allocate memory using the “malloc()” function from the “stdlib.h” header file.
When you’re assigning pointers, ensure that they’re compatible by changing their data type . The following is the updated code for the “charlie” example , and “qwerty” is now an integer.
This article explained why your code made a pointer without a cast and how you can fix it. The following is a summary of what we talked about:
- An attempt to convert an integer to a pointer will lead to the “makes pointer from integer without a cast wint conversion” error.
- To prevent an “incompatible pointer type” error, don’t set a pointer to a different type.
- If you’re using the “printf()” function, and you want to prevent any “pointer to integer” error, always pass a “format specifier”.
At this stage, you’ll be confident that you can work with integers and pointers in C programming without an error. Save our article, and share it with your developer communities to help them get rid of this error as well.
Assignment makes pointer from integer without a cast
- Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems
Thread: Assignment makes pointer from integer without a cast
Thread tools.
- Show Printable Version
- Email this Page…
- Subscribe to this Thread…
- View Profile
- View Forum Posts

I keep getting this error message: "warning: assignment makes pointer from integer without a cast" for line 17 (which I've made red). I've gotten this message a few times before, but I can't remember how I fixed it, and I can't figure out how to fix this one. Any suggestions? Also, it's a code that will take a password entered by the user and then run several for loops until it matches the password. It prints what it's figured out each time it guesses a new letter. Code: #include <stdio.h> #include <string.h> int main(void) { int i, j; char password[25]; char cracked[25]; char *p; char guess = '!'; printf("Enter a password of 25 characters or less: \n"); scanf("%s", password); printf("Password is being cracked..."); for (i = 0, p = password[i]; i < 25; i++, p++) { for(j = 0; j < 90; j++) { if (*p == guess) { strcpy(p, cracked); printf("\t %s \n"); break; } guess++; } //end <search> for loop } //end original for loop return 0; }
Last edited by deciel; 12-13-2011 at 01:57 AM .

Code: for (i = 0, p = password[i]; i < 25; i++, p++) password[i] is the value at index i of password . You want the address of said value, so you want p = &password[i] (or, equivalently, p = password + i ).
Oh! Thank you, it worked!

Originally Posted by deciel I keep getting this error message: "warning: for (i = 0, p = password[i]; i < 25; i++, p++) [/CODE] Note: password[i] == password[0] == *password since this is the assignment portion of for loop and i is set to zero (0).

If you want to set a pointer to the beginning of an array, just use Code: p = password An array name is essentially a pointer to the start of the array memory. Note, for a null terminated string, you could just test for Code: *p //or more explicitly *p == '\0' Also, a 25-element char array doesn't have room for a 25 character string AND a null terminator. And, ask yourself, what's going on when I enter, say a 10 character password, and i > 10.
- Private Messages
- Subscriptions
- Who's Online
- Search Forums
- Forums Home
- C++ Programming
- C# Programming
- Game Programming
- Networking/Device Communication
- Programming Book and Product Reviews
- Windows Programming
- Linux Programming
- General AI Programming
- Article Discussions
- General Discussions
- A Brief History of Cprogramming.com
- Contests Board
- Projects and Job Recruitment

- How to create a shared library on Linux with GCC - December 30, 2011
- Enum classes and nullptr in C++11 - November 27, 2011
- Learn about The Hash Table - November 20, 2011
- Rvalue References and Move Semantics in C++11 - November 13, 2011
- C and C++ for Java Programmers - November 5, 2011
- A Gentle Introduction to C++ IO Streams - October 10, 2011

IMAGES
VIDEO
COMMENTS
A graphical user interface contains six important features, including a pointer, pointing device, icons, desktop, windows and menus. A GUI denotes a collection of computer programs that utilize a computer’s graphics capabilities to make pro...
A Medicare identification number, also known as an HIC Number, is a unique identification code assigned to each beneficiary on his Medicare card. This number is used both for identification purposes and to confirm or deny eligibility for ce...
The QVC channel has 26 hosts, including Albany Irvin, Amy Stran, Dan Wheeler and David Venable. QVC uses casting agencies to find new on-air talent and program hosts. Albany Irvin has been a QVC host since 2009.
3 Answers 3 ... p = (exp + i);. instead. ... do correct the line to correspond to the following p=&(exp[i]); this means that you are assigning the
To fix the “pointer to integer without a cast” in the “printf()” function, pass a “format string” as its first argument. How you write the “format string”
Или initialization makes pointer from integer without a cast ? Почему from? Почему makes, а не does или uses, например? Почему не assignment
assignment makes integer from pointer without a cast c/c++ warning explained #syntax #c/c++ #compiler #error #warning.
assignment to 'char *' from 'int' makes pointer from integer without a cast. · include "main.h” · ifndef MAIN_H · define MAIN_H · include <stdlib.h>.
Пытаюсь сделать функцию - куча ошибок. CВыделить код. 1 2 3 4 5 6 7 8 9 10 11 12
Your trying to read from a pointer without de referencing. It's warning you that the value you get back will be the integer representation
I keep getting this error message: "warning: assignment makes pointer from integer without a cast" for line 17 (which I've made red).
При отладки получаю предупреждение 'Type assignment makes pointer from integer without a cast' На вот такой код: typedef union{ uint16_t
anjolio@desktop:~/Разработка/renamer$ gcc main.c main.c: In function 'main': main.c:8: warning: assignment makes pointer from integer without a cast.
As per my understanding, individuals who transition from Java or C# to C programming often find it challenging to grasp the concept of