Last active
December 7, 2018 07:21
-
-
Save Shylock-Hg/da91db5ba5357c563e03c618fc38d3e2 to your computer and use it in GitHub Desktop.
Some tips ot c/c++.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char * argv[]){ | |
char array[] = "hello"; | |
char * pointer = NULL; | |
// array = "hello"; // error | |
pointer = "hello"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdbool.h> | |
int main(int argc, char * argv[]){ | |
bool t = true; | |
bool f = false; | |
printf("%d,%d\n",t,f); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char * argv[]){ | |
int b = 0b11; | |
int o = 022; | |
int h = 0x33; | |
printf("The value is [%d]!\n", b); | |
printf("The value is [%d]!\n", o); | |
printf("The value is [%d]!\n", h); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class test { | |
private: | |
int * i; | |
public: | |
test(){ | |
i = new int[10]; | |
std::cout << "Construct" << std::endl; | |
} | |
~test(){ | |
delete [] i; | |
std::cout << "Destruct" << std::endl; | |
} | |
}; | |
int main(int argc, char * argv[]){ | |
{ | |
test t; //!< acquire | |
//while(true){}; | |
} //!< release while exit definition scope | |
while(true); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <stdio.h> | |
int main(int argc, char * argv[]){ | |
bool t = false; | |
printf("Sizeof(bool) is %lu.", sizeof(t)); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <string> | |
#include <array> | |
int main(int argc, char * argv[]){ | |
std::vector<int> t = {0, 1, 2, 3, 4, 5}; | |
std::cout << sizeof(t) << std::endl; | |
std::cout << sizeof(std::vector<int>) << std::endl; | |
std::string i = "0123456789"; | |
std::cout << sizeof(i) << std::endl; | |
std::cout << sizeof(std::string) << std::endl; | |
std::cout << sizeof(std::array<int, 32>) << std::endl; // not acquire dynamic resource | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <array> | |
int main(int argc, char * argv[]){ | |
std::cout << "Sizeof(char&) is " << sizeof(char&) << std::endl; | |
std::cout << "Sizeof(char&&) is " << sizeof(char&&) << std::endl; | |
std::cout << "Sizeof(int&) is " << sizeof(int&) << std::endl; | |
std::cout << "Sizeof(int&&) is " << sizeof(int&&) << std::endl; | |
std::cout << "Sizeof(array<int, 33>&) is " << sizeof(std::array<int, 33>&) << std::endl; | |
std::cout << "Sizeof(array<int, 33>&&) is " << sizeof(std::array<int, 33>&&) << std::endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char * argv[]){ | |
int a = -33; | |
int b = 0; | |
a ^= b ^= a ^= b; | |
printf("a is %d, b is %d!\n", a, b); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment