출력과 주석
Coddy의 C++ 개발자를 위한 C 코스 레슨. 48개 중 2번째.
C++의 스트림 삽입은 형식에 맞는 오버로드를 선택합니다. C의 printf는 가변 인수 형식 지정 규약에 의존하며, 변환 지정자가 올바르지 않으면 정의되지 않은 동작이 발생할 수 있습니다. C에는 ostream 추상화가 없습니다.
인수 형식에 맞는 형식 지정자를 사용하세요. 출력 함수는 임의의 객체 형식을 자동으로 추론하지 않습니다.
C++ 예제
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <memory>
#include <algorithm>
#include <functional>
#include <variant>
#include <sstream>
int main(){
std::cout << "value=" << 7 << "\n";
}
C++ 출력:
value=7C 예제
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include <limits.h>
#include <errno.h>
int main(void) {
printf("value=%d\n",7);
return 0;
}
C 출력:
value=7챌린지
쉬움정수와 줄바꿈 문자 하나 앞에 value=를 붙여 출력하도록 announce(value)를 구현하세요. 입력은 정수 하나입니다.
잠금 해제된 소스 파일과 헤더 파일을 수정하세요. 이 함수를 직접 호출하는, 공개된 잠금 상태의 main.c와 선언된 공개 API의 호환성을 유지하세요. main을 추가하지 마세요. 작업에서 명시적으로 범위를 확인하지 않는 한 모든 숫자 작업 테스트 데이터는 오버플로가 발생하지 않을 만큼 작습니다. 지정된 출력만 출력하세요. 표시된 경우 드라이버가 입력 파싱과 출력을 제공합니다.
직접 해보기
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include <limits.h>
#include <errno.h>
#include "lesson.h"
int main(void){int n=0;if(scanf("%d",&n)!=1)return 1;announce(n);return 0;}
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
C++ 개발자를 위한 C의 모든 레슨
직접 연습해 보세요: 온라인 C 컴파일러