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 7703091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:22:47+00:00 2026-05-31T23:22:47+00:00

I am trying to assign the min value of a char to a variable

  • 0

I am trying to assign the min value of a char to a variable of type char array like this

char charchar_value[MAX_VARCHAR_LENGTH + 1]= CHAR_MIN;

it gives me this error “incompatible types in assignment of ‘char’ to ‘char [513]’”

  • 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-31T23:22:48+00:00Added an answer on May 31, 2026 at 11:22 pm

    Initialization of array object requires the use of brace initializer list, i.e. something along the lines of

    char charchar_value[MAX_VARCHAR_LENGTH + 1] = { val_0, val_1, /*...*/ val_n };
    

    This would initialize the first n values to their respective values and all others to zero. This isn’t quite what you want. The only way to set the values in the array is after its initialization, using e.g. std::fill():

    std::fill(std::begin(charchar_value), std::end(charchar_value),
              std::numeric_limits<char>::min());
    

    Since there is another suggestion recommending the using essentially a C approach:

    • The use of memset() is limited to types without any C++ features (as is, indeed the case for char) and when setting the value to something other than 0 it is pretty much limited to char (yes, I realized that there are cases where it would still work). std::fill() on the other hand, works with any type which is CopyAssignable and with any value given to an object of the corresponding type.
    • Although the use of sizeof() work in this case, it won’t work the moment the size becomes dynamic but the compiler would still happily accept the code. Getting the std::begin() or std::end() of a pointer would fail.
    • In a context where the type isn’t exactly know, e.g. when it is a typedef or within a template, std::numeric_limits<T>::min() has a better chance to work. It still won’t work for many type as there is not min() defined but the scope is bigger.

    All that said, I would just use an appropriate class instead which does the initialization directly, i.e.

    std::vector<char> charchar_value(MAX_VARCHAR_LENGTH + 1,
                                     std::numeric_limits<char>::min());
    

    This allocate the memory dynamically, though, i.e. it isn’t entirely equivalent. However, unless there is a good reason to assume otherwise, I would use the simple approach and only optimize if it is necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to assign the following HTML as a value to variable type string
I'm trying to assign the output of cURL into a variable like so: #!/bin/sh
I am trying to assign a theme based on browser type. I would like
I am trying to assign an array length to a variable. servers=(apple orange) len
I'm trying to assign a XMLGregorianCalendar date to a java.sql.Timestamp var, like this... var1.setTimeStamp(Timestamp.valueOf(var2.getXMLGregorianCalendar().toString()))
I am trying to assign objects in an NSMutableArray using this code - (IBAction)variablePressed:(UIButton
I am trying to assign a custom type as a key for std::map .
I'm trying to assign the output of this command ( that is in my
I am trying to assign a regular expression result to an array inside of
I am trying to assign a message to flash[:notice] in a model observer. This

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.