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

The Archive Base Latest Questions

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

Example code: #include <iostream> int main() { if(int a = std::cin.get() && a ==

  • 0

Example code:

#include <iostream>

int main()
{
    if(int a = std::cin.get() && a == 'a')
    {
        std::cout << "True" << std::endl;
    }
}

Question:

When I compile this code, visual studio gives me a nice warning: warning C4700: uninitialized local variable 'a' used. So I understand that a is uninitialized. However, I wanted to fully understand how the expression is evaluated. Is it the case that the if statement above is equivalent to if(int a && a == 'a') { a = std::cin.get(); }? Could someone explain exactly what happens?

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

    The and operator && has higher precedence than the assignment operator =. So in other words, your statement is being executed like this:

    if (int a = (std::cin.get() && a == 'a'))
    

    You really want to use explicit parentheses:

    int a;
    if ((a = std::cin.get()) && a == 'a')
    

    Even better, write clear code:

    int a = std::cin.get();
    if (a == 'a')
    

    🙂

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

Sidebar

Related Questions

I have this example code that doesn't compile: #include <iostream> #include <vector> using std::endl;
Example code: #include <cstdlib> #include <iostream> using namespace std; class A { public: A(int
Example code : int main() { std::vector<int> v1{1, 2, 3, 4, 5, 6, 7,
For example in the following code: #include <iostream> using namespace std; class A {
Very simplified version of my code: #include <iostream> #include <string> using namespace std; int
Is there anyway I can modify this code example #include <stdlib.h> #include <iostream> class
I'm having this weird problem. My code is simple: #include <iostream> using namespace std;
I got surprised when I debugged my code. Here I provide example code #include<QMessageBox>
#include <iostream> class myFunctorClass { public: myFunctorClass(int x) : _x(x) {} int oprator() (int
Using the example code included in the man page for DateTime::Astro::Sunrise , I'm getting

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.