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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:18:20+00:00 2026-05-26T06:18:20+00:00

i have tested two different varianat of similary code ,suppose i have char array

  • 0

i have tested two different varianat of similary code ,suppose i have char array

char x[]="snow comes in winter ";

then following code

#include <iostream>
#include <string.h>
using namespace std;
int main(){

char x[]="snow comes in winter ";
int k=0;
int n=3;
cout<<x+n-k+1<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

prints "comes in winter "
while following

#include <iostream>
#include <string.h>
using namespace std;
int main(){

//char x[]="snow comes in winter ";
int a[]={12,3,2,4,5,6,7};
int k=0;
int n=3;
cout<<a+n-k+1<<endl;



return 0;
}

prints 0xbffd293c
if we change it a bit

#include <iostream>
#include <string.h>
using namespace std;
int main(){

//char x[]="snow comes in winter ";
int a[]={12,3,2,4,5,6,7};
int k=0;
int n=3;
cout<<*(a+n-k+1)<<endl;



return 0;
}

prints number 5.
so my question is why we can access in case of char array so easily?what is main reason of it?i am very curiousy and please could anybody explain me?

  • 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-26T06:18:21+00:00Added an answer on May 26, 2026 at 6:18 am

    why we can access in case of char array so easily?

    Because there’s a convention that C strings are represented by char*, people assume char* are actually strings. The iostreams follow that and overload output for char* to print the string, whereas for an int* (in your second example), they print the representation of the address.

    BTW there is a similar overload for input, which is most unfortunate, since you can’t control that to prevent buffer overflows. ie. don’t do this:

    char x[10];
    std::cin >> x;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't following code work correctly in FireFox 3.6? I have tested in IE7,
I have a stateless EJB and two different SessionScoped managed beans. e.g. EJB as
I have two specs from two different hosts I am using: (a) Dedicated server
We have two different implementations of the same interface. Think of it as a
I have a scenario outline that has two different variables. One variable has about
Suppose we have two longs, x and y. What operator or function involving x
I have two scenarios. Suppose I have 3 shared libraries that export C++ symbols,
I have two functions : void foo(const char * p) and template<size_t T_Size> void
I have tested all my systems developed in Delphi (in Windows XP) on Wine
I have tested the below script on a demo page which is not using

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.