FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
advanced-c-cpp/const-expression.cpp at main · Dpbm/advanced-c-cpp · GitHub
Dpbm
/
advanced-c-cpp
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
advanced-c-cpp
/
const-expression.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (22 loc) · 513 Bytes
Breadcrumbs
advanced-c-cpp
/
const-expression.cpp
Copy path
File metadata and controls
32 lines (22 loc) · 513 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#
include
<
iostream
>
using
namespace
std
;
constexpr
int
calc
(
int
b){
return
b <
10
? b*
10
:
5
;
}
int
main
(){
const
size_t
size =
10
;
int
arr[size];
/*
Error since b is not constant
*/
/*
int b = 10;
*/
/*
constexpr size_t a = b * 10;
*/
const
int
b =
10
;
constexpr
size_t
a = b *
10
;
cout <<
"
a:
"
<< a << endl;
int
result =
calc
(b);
cout <<
"
result:
"
<< result << endl;
int
c =
10
;
int
result2 =
calc
(c);
/*
C doesn't need to be constant
*/
cout <<
"
result2:
"
<< result << endl;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL