C
Posts
19 posts[C++] C2440 : const char[]에서 char*로 변환할 수 없습니다 에러에 관하여
[그림 1] C2440 ERROR 문자열 리터럴을 사용하기 위해서 char* 형태의 변수를 선언했을 때 [그림 1]과 같은 에러가 발생한다.에러의 내용은 "aa"라는 문자열은 const(상수)값인데 변수에 그 값을 집어넣으려고 하니 에러가 발생한다는 것이다. 도대체 이런 에러가 왜 발생하는 걸까? 이런 에러가 발생하는 이유를 MSDN에서는 다음과 같이 설명하고 있다. C2440 can be caused if you attempt to initialize a non-const char* (or wchar_t*) by using a string literal in C++ code, when the compiler conformance option /Zc:strictStrings is set.
[C++] return by reference
123456789101112131415161718192021222324252627#include using namespace std; struct job { char jname[20]; int role; double pay;}; const job & findJob(job &j); int main(){ job j1 = { "DB Design", 1, 100.33 }; job j2; j2 = findJob(j1); cout << j2.role; return 0;} const job & findJob(job &j){ j.role = 2; j.pay += 200.234; return j;
[C++]Magic square
#include "pch.h"#include using namespace std; void magic(int n){ const int MaxSize = 51; int square[MaxSize][MaxSize], k, l; if ((n > (MaxSize)) || (n < 1)) { cerr << "Error! Out of Range!" << endl; return; } else if (!(n % 2)) { cerr << "Error! n is even" << endl; return; } for (int i = 0; i < n; i++)

읽을수 없는 C 컨테스트
프로그래머라면누구나 탐독하는 이 책에서한 문구가 눈에 띕니다. "읽을수 없는 C 콘테스트" 웃고 넘길수 있지만 이런거 찾아봐야죠 그리고http://www.ioccc.org/https://ko.wikipedia.org/wiki/IOCCC실제로 있습니다. 세상에 참 이상한 사람들 많구나.. 참고로이렇게 짜면 수상을 하게 됩니다. ps. 자매품으로 읽기힘든 SQL 콘테스트도 있습니다.https://blogs.oracle.com/sql/obfuscated-sql-contest-winners



