
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program Producing Different Results in C and C++
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