Skip to content

Instantly share code, notes, and snippets.

@Zulqurnain
Created January 10, 2014 09:41
Show Gist options
  • Save Zulqurnain/797c03456187b8be3764 to your computer and use it in GitHub Desktop.
Save Zulqurnain/797c03456187b8be3764 to your computer and use it in GitHub Desktop.
C++ code to add Two number without using any operator .
#include<iostream>
using namespace std;
/*
Reason: when we are doing p[i] it is actually equall to *(p+i) ,
similarly when we are doing &p[i] it is equal to (p+i) so giving address,
when we do &((&p[a])[b]) is it equall to (p+a+b) , p=0 so 0+a+b = a+b ,
i have used integer type casting because pointer p was of character type
*/
int main(){ // By Zulqurnain jutt
int a=1,b=0;
char *p=0;
cout<<"a + b :=:"<<(int)(&((&p[a])[b]))<<"\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment