Search code examples
ccharinitializationprintfstring-literals

another "initialization makes integer from pointer without a cast" error i didnt understand


This code is supposed to print valuesa and adresses of variables using variable and pointer names and adresses. I get this initialization makes integer from pointer without a cast error.


#include <stdio.h>      
    
int main() {

    int m = 300;
    double fx = 300.6006;
    char z = "c";

    printf("%d\n %lf\n %c\n", m, fx, z);
    printf("%p\n %p\n %p\n", &m, &fx, &z);  

    int* ptr_m = &m;
    double* ptr_fx = &fx;
    char* ptr_z = &z;

    printf("%d\n %lf\n %c\n", *ptr_m, *ptr_fx, *ptr_z);
    printf("%p\n %p\n %p\n", &ptr_m, &ptr_fx, &ptr_z);

    return 0;
}

Can you help me fix this ?


Solution

  • Replace:

    char z = "c";
    

    with

    char z = 'c';