Thread: Its a bug ?? c++

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    5

    Its a bug ?? c++

    See the code:

    Code:
    #include<iostream>
    
    using namespace std;
    
    
    int main()
    {
        int a;
        cin>>a;
        cin.ignore();
    
    
        int b = 2;
        cout<<b;
    
    
       return 1;
    }
    When I run the program and I put a data in the variabe a(ex: a = 3). Show me 3 and 2. Why??

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,489
    Well what did you expect to see?

    The 3 is what you typed, and the 2 is what the program printed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2017
    Posts
    6
    Salem above answers it correctly though sarcastically, Lol!!
    Last edited by Salem; 11-12-2017 at 02:12 AM. Reason: Removed fake signature

Popular pages Recent additions subscribe to a feed

Tags for this Thread