Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 736523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:36:52+00:00 2026-05-14T07:36:52+00:00

char char* c[30]; c = (char*) malloc(30*sizeof(char) ); How does this give an incompatible

  • 0
 char 
 char* c[30];
    c = (char*) malloc(30*sizeof(char) );

How does this give an incompatible declaration in built in function warning and and incompatible types in assignment error in the line where i have declared malloc . According to the syntax of malloc , i shouldnt have any error

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:36:53+00:00Added an answer on May 14, 2026 at 7:36 am

    You have declared c as an array. You can’t change the value of an array, and an array is not a pointer.

    c has the type (char*)[30](i.e. an array of 30 char pointers) , not char* as your cast suggests.

    If you’re trying to create a dynamically allocated char “array” for 30 chars, use

    char *c = malloc(30);
    

    If you really want an array of 30 char pointers, and e.g. allocate space for 30 chars in each of its elements, use

    int i;
    for(i = 0; i < sizeof c/sizeof c[0]; i++) {
      c[i] = malloc(30);
      if(c[i] == NULL) {
        //handle error
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused about malloc() function. if sizeof(char) is 1 byte and the
I usually use pointers in the following manner char *ptr = malloc( sizeof(char) *
static char st[][8192]; void foo ( int tab_size){ st = (char**) malloc ((tab_size+1)*sizeof(char)*8192); }
int length = strlen(src); char *structSpace = malloc(sizeof(String) + length + 1); String *string
Consider this code: char buffer[] = abcdefghijklmnopqrstuvwxyz, *val = malloc(10), *pbuf = buffer, *pval
Hi I ran in to this situation. I am using malloc to give me
int main() { char *s1, *sTemp; s1 = (char*)malloc(sizeof(char)*7); *(s1 + 0) = 'a';
#inlcude <stdio.h> #inlcude <stdlib.h> #inlcude <string.h> int main() { char *buff = (char*)malloc(sizeof(char) *
I'm a little bit confused about this expression: char *s = abc; Does the
int *ptr = malloc(sizeof(char)); *ptr = 100000; printf("%d\n", *ptr); // 100000 Shouldn't that only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.