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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:28:36+00:00 2026-06-07T23:28:36+00:00

bool foo( int* p ) { return false; } int* bar ( ) {

  • 0
bool foo( int* p )
{
  return false;
}

int* bar (  )
{
  int* p;
  return p;
}

int main() {

  if ( int* p = bar() && foo( p ) )
  //if ( ((int* p = bar()) != NULL ) && (foo( p )) ) // another variant
  {

  }

  return 0;
}

I get error: cannot convert ‘bool’ to ‘int*’ in initialization with GCC 4.3.4 and VS 2008. If there is only if ( int* p = bar()) everything works fine.

I know i can initialize p before if-statement, but i’m interested in the variant i shown.

  • 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-07T23:28:37+00:00Added an answer on June 7, 2026 at 11:28 pm

    The syntax of an if requires a condition in the parentheses. A
    condition can be either an expression, or a declaration (of a
    type with an implicit conversion to bool); it cannot be a combination
    of these. In the case of

    if ( int* p = bar() && foo( p ) )
    

    , the condition is “int* p = bar() && foo( p )“, which is a simple
    declaration of a type int* initialized with bar() && foo( p ); since
    the type of bar() && foo( p ) isn’t int*, and can’t be implicitly
    converted into an int*, you have an error.

    If you write:

    if ( (int* p = bar()) != NULL )
    

    , the opening parentheses mean that this cannot be a declaration (simple
    or no), and int* p = bar() isn’t a legal (sub-)expression.

    The critical point to remember is that you can have a declaration, or
    you can have an expression, but that you can’t combine them, and the C++
    doesn’t allow declarations as part of an expression. (Also: the
    declaration must have copy initialization:

    if ( int* p = bar() )
    

    , direct initialization is not allowed.)

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

Sidebar

Related Questions

I have the following structure $('foo').click( function() { var bool = false; $('bar').animate( function()
I have wery little code: // prototype bool Foo(); int main( ... ) {
I am trying to convert as following: bool foo(int a, unsigned short b) {
Suppose we have: interface Foo { bool Func(int x); } class Bar: Foo {
Is there a way to get the following function declaration? public bool Foo<T>() where
bool hasDuplicate = false; int[] a = new int[] {1, 2, 3, 4}; int[]
bool isValid = false; string username = someadmin; If( !String.IsNullOrEmpty(username) && !( username.IndexOf(admin) !=
bool is_something_ok(int param,SomeStruct* p) { bool is_ok = false; // check if is_ok if(is_ok)
Say I have the following function: bool foo (int a); // This method declaration
Question: Given the following code snippet: bool foo(int n) { for(int i=3;i<sqrt(n)+0.5;i+=2) { if((n%i)==0){

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.