C++ #define elif else if

Python中有一个函数"elif",相当于C++的"else if",

而C++的define可以制作一些奇怪的代码,

所以我们能在C++中做一个——"elif";

#define elif else if

然而这太简单了,所以我们要再增加一点。

#include<iostream>
using namespace std;
#define elif else if
int n;
int main()
{
    cin>>n;
    if(n==1654) cout<<"YES";
    elif(n==1928374650) cout<<"R";
    else cout<<"NO";
    return 0;
}

不喜勿喷

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#if, #elseif, and #endif are preprocessor directives commonly used in programming languages such as C, C++, and C#. These directives are used to conditionally compile code based on certain conditions. The #if directive allows you to test a condition and include or exclude code based on the result. It is followed by a condition, which can be a defined constant, a macro expression, or a combination of these. If the condition evaluates to true, the block of code following the #if directive is compiled. Otherwise, it is skipped. The #elseif directive is used to test an additional condition if the preceding #if or #elseif condition(s) evaluated to false. It provides an alternative condition to be checked. If the condition evaluates to true, the block of code following the #elseif directive is compiled. Otherwise, it is skipped. The #endif directive marks the end of a conditional block. It is used to close the block of code associated with the most recent #if or #elseif directive. Here's an example usage of these directives in C: ```c #define DEBUG_MODE #if defined(DEBUG_MODE) printf("Debug mode is enabled.\n"); #elif defined(TEST_MODE) printf("Test mode is enabled.\n"); #else printf("No special mode is enabled.\n"); #endif ``` In this example, if the `DEBUG_MODE` macro is defined, the code within the first block will be compiled and executed. If not, it will check for the `TEST_MODE` macro and execute the code within the second block if it is defined. If neither macro is defined, the code within the else block will be executed.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值