I have question about character data type in c++.
Suppose i have the following code.
int main(){
char x= '123';
cout<
}
if i change x to something else, say '17', i get output as 7.
if i change it to something else, like 7 . i get same output 7. again
if i change it again to something else , like '1', i get 7 again
but if i change it to '11' , i get 1. or to '1839', i get 9.
Why is the code giving same output for some different values and vise versa .
In all cases, i was expecting the out to be same as the character inside the single quotation and how is the first code different the one below??
int main(){
char x= 123;
cout<
}
Thank you
In Programming Language C++, we can assign multi characters to a character data type and which value will be assigned to the character variable depends upon the implementation.
A multi characters literal is an ordinary character literal that contains multiple characters.
Internally character data type is working as an integer data type. ASCII code is assigned to each of the character.
For example:
ASCII code of 'A' is 65
ASCII code of 'a' is 97
When we initialise a character type variable with a character literal then that literal is converted into an integer value and then stored.
Most of the implementation of multi character literals uses successive bytes to store the multi character literal or integer values.
A multi-character literal has implementation-defined value and type int.
So, we can't say that the last character will be assigned always because it is implementation dependent value but most of the implementation assign the last character only.
Let us see the below statement:
char x= 123;
The above statement will assign the value 123 the the character variable and it will work fine. When we will print the value assigned to the character then it will print the character which has ASCII code 123 and character '{' has the ASCII code 123.
So, the below statement:
cout<<x;
will print '{' as an output.
For example:
char x= 65;
cout<<x; //this statement will print 'A' because 65 is the ASCII value of 'A'
char x= 97;
cout<<x; //this statement will print 'a' because 97 is the ASCII value of 'a'
I have question about character data type in c++. Suppose i have the following code. int main(){...
Task: if the character read in is a '.' (dot), ',' (comma), '?' (question mark), '-' (dash), or a "'" (single quote), then it is replaced by a ' ' (space) character unless these characters appear inside a double quotation-mark enclosed substring; and, if the character is not a '.' (dot), '.' (comma), '?' (question mark), '-' (dash), or a "'" (single quote), then it is always output as-is. You program must process all input from standard input (i.e., std::cin)...
The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() { char board[SIZE]; int player, choice, win, count; char mark; count = 0; // number of boxes marked till now initBoard(board); // start the game player = 1; // default player mark = 'X'; // default mark do { displayBoard(board); cout << "Player " << player << "(" << mark...
/// c ++ question plz help me fix this not a new code and explain to me plz /// Write a function to verify the format of an email address: bool VeryifyEmail(char email[ ]); Do NOT parse the email array once character at a time. Use cstring functions to do most of the work. Take a look at the available cstring and string class functions on cplusplus website. Use a two dimensional array to store the acceptable top domain names:...
QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...
C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...
I have the following code in C: void sighandler(int sig) { printf("exiting child..."); } int main(int argc,char* argv[]) { if(argc > 1) { char* commandName; for(int i=2;i { forkChild = fork(); signal(SIGINT,sighandler); if(forkChild == 0) { execlp(commandName,commandName,argv[i],NULL); exit(0); } else { wait(NULL); } } My problem is that I would like to kill the child with ^C but leave the parent running....
How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0, b = 1, c; if (n <= 1) return n; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int fibonacciRecursive(int n) { if (n <= 1) { return n; } return fibonacciRecursive(n-1) + fibonacciRecursive(n-2); } int main() { int n;...
I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in: "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...
Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2 - Stack around the variable 'string4b' was corrupted. I need some help because if the arrays for string4a and string4b have different sizes. Also if I put different sizes in string3a and string4b it will say that those arrays for 3a and 3b are corrupted. But for the assigment I need to put arrays of different sizes so that they can do their work...
so i have my c++ code and ive been working on this for hours
but i cant get it to run im not allowed to use arrays. im not sure
how to fix it thank you for the help
our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses...