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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:36:35+00:00 2026-05-25T23:36:35+00:00

Can anyone please explain what is going in this C++ code. It compiles and

  • 0

Can anyone please explain what is going in this C++ code. It compiles and executes fine on Linux.

#include <iostream>
using namespace std;
int main = ( cout << "Hello world!\n", 195 );
  • 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-25T23:36:35+00:00Added an answer on May 25, 2026 at 11:36 pm

    The number “195” is the code of RET instruction on x86.

    The C++ compiler (gcc in my case) is unable to recognize that “main” wasn’t declared as a function. The compiler only sees that there is the “main” symbol, and presumes that it refers to a function.

    The C++ code

    int main = ( cout << "Hello world!\n", 195 );
    

    is initializing a variable at file-scope. This initialization code is executed before the C/C++ environment calls main(), but after it initializes the “cout” variable. The initialization prints “Hello, world!\n”, and sets the value of variable “main” to 195. After all initialization is done, the C/C++ environment makes a call to “main”. The program returns immediately from this call because we put a RET instruction (code 195) at the address of “main”.

    Sample GDB output:

    $ gdb ./a
    (gdb) break _fini
    Breakpoint 1 at 0x8048704
    (gdb) print main
    $1 = 0
    (gdb) disass &main
    Dump of assembler code for function main:
       0x0804a0b4 <+0>:     add    %al,(%eax)
       0x0804a0b6 <+2>:     add    %al,(%eax)
    End of assembler dump.
    (gdb) run
    Starting program: /home/atom/a 
    Hello world!
    
    Breakpoint 1, 0x08048704 in _fini ()
    (gdb) print main
    $2 = 195
    (gdb) disass &main
    Dump of assembler code for function main:
       0x0804a0b4 <+0>:     ret    
       0x0804a0b5 <+1>:     add    %al,(%eax)
       0x0804a0b7 <+3>:     add    %al,(%eax)
    End of assembler dump.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can anyone please explain this code? #include <avr/io.h> #include <avr/interrupt.h> #include <avr/signal.h> char n
My first time using triggers. Can anyone please explain why this trigger won't work?
Can anyone please explain the behavior of this piece of code(from http://blogs.msdn.com/b/wesdyer/archive/2007/02/02/anonymous-recursion-in-c.aspx ). I
Can anyone please explain me about carp subroutine with sample Perl code?
the following code is a textmate javascript snippet, can anyone explain it please? cuz
Can anyone please explain a recursive function to me in PHP (without using Fibonacci)
Can anyone please explain me how silverlight code gets executed.For example in asp.net if
can anyone please explain how this works (asz + 7) & ~7; It rounds
I have this Erlang code: not lists:any(fun(Condition) ->Condition(Message) end, Conditions). Can anyone please explain
Can anyone please explain what the following code checks for? I can make no

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.