Can the source running in both C and C++ produce different results?

Asked 2 years ago, Updated 2 years ago, 37 views

C and C++ are different languages. Not all C-codes work in C++.

Then Is there a code that produces different results between C and C++ sources?

Except for preprocessors and type limits, If it's different depending on the version, please tell me which version works or doesn't work!

c++ c

2022-09-22 22:36

1 Answers

The following code runs on both C and C++, but results in different results. int i = sizeof('a'); In C, it's 4 In c++, it's 1.

Another thing is

#include <stdio.h>

int  sz = 80;

int main(void)
{
    struct sz { char c; };

    int val = sizeof(sz);
    printf("%d\n", val);
    return 0;
}

In c, size of(int) is In c++, sizeof(structuresz).


2022-09-22 22:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.