This question already has answers here:
C++11 range based loop: How does it really work
(3 answers)
Range based for-loop with &
(3 answers)
How to correctly implement custom iterators and const_iterators?
(9 answers)
How to make my custom type to work with "range-based for loops"?
(10 answers)
Closed 21 days ago.
Since I am new to C++, I do not know what the expression means?
and how can i co-relate this expression with C language.
#include <bits/stdc++.h>
using namespace std;
int main()
{
// string to be converted to lowercase
string s = "GEEKSFORGEEKS";
for (auto& x : s) {
x = tolower(x);
}
cout << s;
return 0;
}
Related
This question already has answers here:
Passing Arrays to Function in C++
(5 answers)
Variable length arrays (VLA) in C and C++
(5 answers)
What is array to pointer decay?
(11 answers)
Closed 4 months ago.
This program is to find Frequency of different elements in array using unordered map. But I am unable to debug it, as this error is occuring for the first time in my code. Please help me debug this code.
#include<iostream>
#include<unordered_map>
using namespace std;
void frequency(int arr[] , int n)
{
unordered_map<int,int> m;
for(int x : arr) /* This line is showing error(for statement require a suitable begin function and none was found .)*/
m[x]++;
for( auto x : m)
cout<<x.first<<" : "<<x.second;
}
int main()
{
int n = 8;
int arr[n] = {10,12,10,15,10,20,12,12};
frequency(arr,n);
}
This question already has answers here:
size of array passed to C++ function? [duplicate]
(7 answers)
determine size of array if passed to function
(10 answers)
Sizeof in function [duplicate]
(1 answer)
Closed 6 months ago.
#include<iostream>
#include <string>
using namespace std;
void show_length(int array1[]){
int length=sizeof(array1)/sizeof(array1[0]);
cout<<"Length inside function = "<<length<<"\n";
}
int main(){
int array1[6]={3,6,4,2,1,4};
int length=sizeof(array1)/sizeof(array1[0]);
cout<<"Length inside main = "<<length<<"\n";
show_length(array1);
system("pause");
}
i recive 6 as an answer in the main (which is the right answer) but 2 in the separate function, why this happens?
This question already has answers here:
C macros and use of arguments in parentheses
(2 answers)
C Programming Macros multiplication [duplicate]
(2 answers)
Closed 2 years ago.
#include <iostream>
using namespace std;
#define MULTIPLY(a, b) a*b
int main(){
cout << MULTIPLY(2+3, 3+5);
return 0;
}
I expected this to print 40 since five times eight is forty. Why does it print 16?
Because C++ macros are not functions. They are text copies, so that means:
cout << 2+3*3+5;
Which is 2 + (3*3) + 5
This question already has answers here:
What are the differences between C-like, constructor, and uniform initialization?
(2 answers)
Initialization difference with or without curly braces in C++
(3 answers)
What are the advantages of list initialization (using curly braces)?
(5 answers)
Closed 4 years ago.
In c++ what is the difference between initializing an object with round or angled braces like in this example?
#include <iostream>
#include <string>
int main()
{
std::string x = "abc";
std::string c(x);
//std::string c{x};
std::cout << "String c " << c;
return 0;
}
This question already has answers here:
integer indexed with a string in c++ [duplicate]
(3 answers)
With arrays, why is it the case that a[5] == 5[a]?
(20 answers)
Closed 4 years ago.
Consider the below syntax :
#include <iostream>
int main() {
std::cout << 1["ABC"] << std::endl;
}
The program outputs B which leads me to believe that it behaves as "ABC"[1]. Is that possible, what is the reason behind this ?