What's the meaning of the caret sign ^ in fortran - fortran

Given i have a variable in fortran programming declared as a = 50 , b = 40
what is the result of variable c = a ^ 2? does this sign ^ represent modulo?

No, ^ is not an operator in fortran.

Related

What is the (...) called in C and C++?

One of the uses of ... is to denote variadic entities in C and C++.
What is its name?
Is it classified as an operator or something else when used that way?
Any other details regarding ...?
Edit: I know the purpose of .... I am asking about its name and classification, which I hope, is similar in C and C++.
It is one of the punctuators.
6.4.6 Punctuators
Syntax punctuator:
one of [ ] ( ) { } . ->
++ -- & * + - ~ !
/ % << >> < > <= >= == != ^ | && ||
? : ; ...
= *= /= %= += -= <<= >>= &= ^= |=
, # ##
<: :> <% %> %: %:%:
In the function declaration it is called the ellipsis.
Ellipsis is also used by some compiler C language extensions.
Example - gcc switch/case range extension
const char *test(unsigned num)
{
switch(num)
{
case 0 ... 9:
return "the value is in the 0 to 9 range";
case 10 ... 99:
return "the value is in the 10 to 99 range";
default:
return "out of tested range";
}
}
https://godbolt.org/z/YBLma-
The ... is referred to as an ellipsis both in English and in the C standard.
One of the uses of ... is to denote variadic entities in C and C++.`
Yes, In layman's terms ... can be thought of as denoting more than one or multiples (as in pseudo-code punctuation we sometimes use multiple dots to resemble different types) of a use case, for which if we consider variadics (being multiple in the sense of 'varying' arguments/parameters) in C++, it would refer to a variable number of arguments for functions or templates.
What is its name?
Ellipsis
Is it classified as an operator or something else when used in that way?
No, it's definitely not an operator as it allows you to pass any number of arguments, not operate on them.
Any other details regarding ...?
As far as I know -
Its a special specifier;
The ellipsis always comes last in the argument list;
As far as its usage is concerned, its only used when you want to remove the limits on the number of parameters for a template/function or when you require to have an extensible number of parameters for expansion. (i.e. it provides parameter pack expansion in a variadic class template or function template) In practice we mostly require a fixed set of known parameters, so it isn't applicable to most cases;
It can be used with sizeof operator, as it's classified as a pack expansion as well.
Edit: I know the purpose of ... I am asking about its name and classification, which I hope, is similar in both C and C++.
The name is same, but usage may vary for C++ and C.
Am only familiar with its use in the former language. (I remember having a HackerRank problem on Variadics, covering its utility.)
The sequence of three full stops ... is called an ellipsis in both C and C++
In C++, the ellipsis helps initialize and expand different kinds of packs.
A parameter pack - when there is an ellipsis between the type and the identifier
Type ... identifier
A pack expansion - consists of a pattern and an ellipsis
pattern...

How to understand following single and double quotes terminology in C++?

Help me understand the following:
cout<<'a'; //prints a and it's okay but
cout<<'ab'; //prints 24930 but I was expecting an error due to term 'ab' having two character in single quote
cout<<'a'+1; //prints 98
cout<<"ab"; // prints ab and it's okay but
cout<<"ab"+1; // prints b, why?
cout<<"a"+1; // prints nothing ?
cout<<'a'+'b'; // prints 195 ?
cout<<"a"+"b"; // gives error ?
Please help me to understand all these things in details. I am very confused. I would be very thankful.
'a' is a char type in C++. std::cout overloads << for a char to output the character, rather than the character number.
'ab' is a multicharacter literal in C++. It must have an int type. Its value is implementation defined, but 'a' * 256 + 'b' is common. With ASCII encoding, that is 24930. The overloaded << operator for an int outputs the number.
'a' + 1 is an arithmetic expression. 'a' is converted to an int type prior to the addition according to the standard integral type promotion rules.
"ab" + 1 is executing pointer arithmetic on the const char[3] type, so it's equivalent to "b". Remember that << has lower precedence than +.
"a" + 1 is similar to the above but only the NUL-terminator is output.
'a' + 'b' is an int type. Both arguments are converted to an int prior to the addition.
The arguments of "a" + "b" decay to const char* types prior to the addition. But that's the addition of two pointers, which is not valid C++.

what is wrong with error: invalid operands to binary expression ('double' and 'double')

for output from one line of my code
double _double = pow(((15) ^ 17)/11 ^ 1.5,2)/9.8;
when I try to compile it, it returns error: invalid operands to binary expression ('double' and 'double')
I think both 15 ^ 17 and 11 ^ 1.5 would be double, so why it gave me this error?
The compiler gives you an error because ^ in C++ does not do what you think it does. It is a XOR operator, not a power operator, and it works only on integral data types. For example, 15 ^ 17 is 30:
01111 // 15
XOR 10001 // 17
---------
11110 // 30
In fact, C++ lacks the power operator altogether. You should use std::pow(double,double) instead:
double _double = pow(pow(15, 17)/pow(11, 1.5), 2)/9.8;
You cannot operate two doubles with XOR (^). It only works with int, long, bool, short, char and their variations. No floating-point datatypes.
double _double = pow(((15) ^ 17)/11 ^ 1.5,2)/9.8;
The ^ operator is the logical exclusive or operator.
To exponentiate numbers, use pow, like you do.

Why is this double initialization with a comma illegal?

I have three code snippets. This one:
1,7; //yes, that's all the code
compiles okay. This one:
double d = (1, 7);
also compiles okay. Yet this one:
double d = 1, 7;
fails to compile. gcc-4.3.4 says
error: expected unqualified-id before numeric constant
and Visual C++ 10 says
error C2059: syntax error : 'constant'
Why such difference? Why don't all the three compile with , having the same effect in all three?
In the first two cases, the statements are using C++'s comma operator
In the latter case, comma is being used as variable separate and the compiler is expecting you to declare multiple identifiers; the comma is not being used as the operator here.
The last case is similar to something like:
float x,y;
float a = 10, b = 20;
When you do this:
double d = 1, 7;
The compiler expects a variable identifier and not a numeric constant. Hence 7 is illegal here.
However when you do this:
double d = (1,7);
the normal comma operator is being used: 1 gets evaluated and discard while 7 is stored in d.
The difference is that in 1, 7; and (1, 7) you have expressions where a comma operator is allowed.
Your last example
double d = 1, 7;
is a declaration, where the comma isn't an operator but a separator. The compiler exepcts something like
double d = 1, e = 7;
which would be a correct variable declaration.
Note that the comma is sometimes an operator (in expressions), but is also used as a separator in other places like parameter lists in function declarations.
double d = (1, 7); Here the (1, 7) will be evaluated
first; the comma works as sequential-evaluation operator, and
7 will be assigned to d.
double d = 1, 7; In this case there is a problem: the part
before the comma means you declare a double and set its value, but
the part after the comma is meaningless, because it's just a single
integer constant.
I believe it is because the last one is treated as (incorrect) declaration line: (double d = 1), (7)

How does the compiler interpret this expression?

While reading through a C++ book, I came across an expression which was not explained properly (or maybe I just didn't understand the explanation). This is the expression:
c = a+++b;
Which of these does it mean?
c = a + (++b); // 1
c = (a++) + b; // 2
Thanks.
Its interpreted as:
c = a++ + b; //which is same as you're ve written : (a++) + b
Its following the Maximal munch rule.