- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a program that produces different results in C and C++ programming
Write a program that compiler and runs both in c and c++ and produces different results.
There are multiple types of programs that give different results when compiled in c and c++.
i. Using character literals− c and c++ both treat characters differently. In C, they are treated as integer literals whereas, in C++, they are treated as characters.
Example
#include<stdio.h> int main(){ printf("%d", sizeof('a')); return 0; }
Output
C : 4 C++: 1
ii. Use of binary number − binary values are not considered as binary in c, instead treat it as integer. But in c++, they are treated as binary.
Example
#include<stdio.h> int main(){ printf("%d", sizeof(1!=1)); return 0; }
Output
C : 4 C++: 1
Advertisements