C++ data types
See here for an introduction to the data types provided by C++.
Let's explore some data types. Consider this code - it initializes an 'unsigned short' to 0 and decrements it. Will it become negative, though it is unsigned?
unsigned short int i = 0;
i--;
Try it out and check the value of the variable after decrementing.
Consider that the variable i is used to index an array:
char name[] = "Helloo";
char c = name[i];
What would be the outcome of accessing the array in the second line?
Let us know your thoughts below. Next, we look at variables in C++ and their scope.
As variable i has a large value greater than the size of name[] array, so accessing the ith index will throw a runtime error "SIGSEGV".
ReplyDelete