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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:44:50+00:00 2026-05-15T08:44:50+00:00

const int t=5; char buf[t+5]; When I compile this gives error in C but

  • 0
const int t=5;
char buf[t+5];

When I compile this gives error in C but not in C++!!
Can anybody please explain me the reason?

Note: I know the const defaults to internal linkage in ‘C++’, where as in ‘C’ it defaults to external linkage. Does it has any relation to the above case??

  • 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-15T08:44:50+00:00Added an answer on May 15, 2026 at 8:44 am

    As others explained, C is kept more simple than C++ and doesn’t allow const variables to appear in integer constant expressions. But in both C89 and C++ declared arrays must have compile-time constant sizes.

    You can use enumerations for this

    enum {
      BufSize = 5
    };
    
    char buf[BufSize + 5];
    

    It doesn’t have to do with internal linkage – external linkage variables are equally viable in integer constant expressions in C++. The internal linkage in C++ rather is a consequence, but not a neccessity, of allowing them to appear in constant expressions. The C++ Standard explains why they have internal linkage by default

    Because const objects can be used as compile-time values in C++, this feature urges programmers to provide explicit initializer values for each const. This feature allows the user to put const objects in header files that are included in many compilation units

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

Sidebar

Related Questions

It made some errors like this: KDnsCache.cpp: In member function ‘unsigned int KDnsCache::GetName(const char*)’:
I have these strings: int name const int level const char * const format
i have the following code below: const char* timeformat = %Y-%m-%d %H:%M:%S; const int
int KMP( const char *original, int o_len, const char *substring, int s_len ){ if(
Say I have something along the lines of: int main() { const char* someString
I have a function as below extern C int FuncTrace(const char *fmt, ...) {
I have the following piece of code compiling under gcc: int parseMsg(const char *msg_to_parse,
I have a simple C function which I declare as: int strLen(const char* str_)
The following code #include <iostream> using namespace std; int main() { const char* const
#include <iostream> using namespace std; int main (int argc, char* const argv[]) { int

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.