인프런 커뮤니티 질문&답변
[연습문제 풀이]
작성
·
185
1
<code>
#include <iostream>
using namespace std;
int main()
{
char name[] = "Jack jack";
const int n_name = sizeof(name) / sizeof(name[0]);
char *ptr = name;
// 첫 번째 시도
int i = 0;
while (i < n_name)
{
if (*(ptr + i) == '\0')
break;
cout << *(ptr + i);
++i;
}
cout << "##" << endl; //널 캐릭터 확인용
// cout << *(ptr++) << endl;
// cout << *(ptr++) << endl;
// cout << *(ptr++) << endl;
// cout << *(ptr++) << endl;
// 두 번째 시도, 굳이 조건이 n_name이 아니어도 됐을 텐데...
while (n_name)
{
if (*ptr == '\0')
break;
cout << *(ptr++);
}
cout << "##" << endl; //널 캐릭터 확인용
// for (int i = 0; i < n_name; ++i)
// {
// // cout << char(toupper(name[i])) << endl;
// cout << *(ptr + i);
// }
// cout << "##" << endl;
// cout << endl;
// long long array[] = {9, 7, 5, 3, 1};
// long long *ptr = array;
// for (int i = 0; i < sizeof(array) / sizeof(array[0]); ++i)
// {
// cout << *(ptr + i) << " " << (uintptr_t)(ptr + i) << endl;
// }
// short value = 7;
// short *ptr = &value;
// cout << uintptr_t(ptr - 1) << endl;
// cout << uintptr_t(ptr) << endl;
// cout << uintptr_t(ptr + 1) << endl;
return 0;
}
<output>
PS C:\coding\tbc_review\TBCPP\Chapter6> g++ .\6_9.cpp
PS C:\coding\tbc_review\TBCPP\Chapter6> .\a.exe
Jack jack##
Jack jack##
답변
답변을 기다리고 있는 질문이에요
첫번째 답변을 남겨보세요!





