Hello, I know that both perform type deduction, but what is the difference between the two? When is it more convenient to use decltype
envelope auto
and vice versa?
cheroky's questions
Well, I am very interested in learning about this apparently useful new feature, but it is difficult for me because all the quality information available is in English. In the same way I try to learn but my English is not so good that I can only understand a few things. That is why I am asking here if someone could explain what the semantics of movement are and the details that go with it.
What I have to do is store a randomly selected pair of characters in a matrix and print it like this.
? # ¡ x
x ? # ¡
0 - + *
+ 0 - *
The problem is that I can't find a way to mark the characters that have come out twice, so as not to include them anymore.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char a[4][4];
char cartas[]={'#','%','@','0','*','!','<','x'};
int total=sizeof(cartas);
int main()
{
srand(time(0));
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
a[i][j]=cartas[rand()%total];
printf("\t%c",a[i][j]);
}
printf("\n\n");
}
}
Does anyone know of a way?
I have seen articles in English that talk about this, as far as I can understand they are used for encapsulation in C. Can someone explain what exactly is an incomplete type and an opaque pointer? And what uses do they have in C?
Can someone explain why interpreting a float as an integer as I understand data would be lost, is it a valid C casting?
float sqrt7(float x)
{
unsigned int i = *(unsigned int*) &x;
i += 127 << 23;
i >>= 1;
return *(float*) &i;
}
In addition, after it is cast again to float, it is the first time that I see this type of code
Since in C/C++ floating-point literals without a suffix default to type double , then assigning such a literal to a float performs an implicit conversion from double to float .
float n = 3.14;
if(n == 3.14f)
puts("Igual");
This does not print the message instead if we add the suffix f to 3.14 in the declaration of n to prevent the conversion if printed. The question is, is there a loss of precision when the conversion is carried out?
To check if it is possible I did the following:
try
{
int *x = 0;
*x = 1234;
}
catch(...)
{
cout << "OK";
}
But when I run it, I still get a segfault. I've read on some sites that try/catch can't catch a segfault, but I don't know if that's true, could someone please confirm that for me.