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

  • Home
  • SEARCH
  • 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 7954015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:17:54+00:00 2026-06-04T03:17:54+00:00

In the following code I got confused and added a + where it should

  • 0

In the following code I got confused and added a + where it should be <<

#include <iostream>
#include "Ship.h"

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    char someLetter = aLetter(true);
    cout <<"Still good"<<endl;
    cout << "someLetter: " + someLetter << endl;
    return 0;
}

Should be

cout << "someLetter: " << someLetter << endl;

The incorrect code outputted:

Hello world!
Still good
os::clear

What I don’t understand is why the compiler didn’t catch any errors and what does os::clear mean? Also why wasn’t “someLetter: ” at the start of the line?

  • 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-06-04T03:17:55+00:00Added an answer on June 4, 2026 at 3:17 am

    Here, "someLetter: " is a string literal, i.e. a const char * pointer, usually pointing to a read-only area of memory where all the string literals are stored.

    someLetter is a char, so "someLetter: " + someLetter performs pointer arithmetic and adds the value of someLetter to the address stored in the pointer. The end result is a pointer that points somewhere past the string literal you intended to print.

    In your case, it seems the pointer ends up in the symbol table and pointing to the second character of the name of the ios::clear method. This is completely arbitrary though, the pointer might end up pointing to another (possibly inaccessible) location, depending on the value of someLetter and the content of the string literal storage area. In summary, this behavior is undefined, you cannot rely on it.

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

Sidebar

Related Questions

I'm confused about an aspect of polymorphism. Please consider the following code: #include <iostream>
I have the following code and got myself confused: I have a query that
I got confused when I tried to parse following xml using libxmljs: <?xml version=1.0
i was dealing with the following code,& got confused,please have a look at it
I'm a little confused here. I've got the following code: class Users { function
I've got following code in my AsyncTask. The only thing I want the AsyncTask
I got following code in an XHTML-document and every browser saysit is malformed :(
I got following code from net and it looks everything is proper but i'm
I've got the following code: try { ... try { // This is *never*
I've got the following code that's taking photos from a flickr feed via JSON

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.