Question

Which of the following would constitute a narrowing conversion in C++? Converting a char into an...

Which of the following would constitute a narrowing conversion in C++?

Converting a char into an int.

Converting an int into a short.

Converting a float into a double.

Converting a char into an int*.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Narrowing means assigning value to a variable not capable of holding it. For eg . assigning numeric to other numeric not capable of holding it because of less size.

for eg.

converting int to short. short has less size, so its not capable of holding an int value. this is called narrowing.

so b) is correct

Add a comment
Know the answer?
Add Answer to:
Which of the following would constitute a narrowing conversion in C++? Converting a char into an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Give the minimum size of each of the following C++ types, assuming that char values occupy one...

    2. Give the minimum size of each of the following C++ types, assuming that char values occupy one byte, short values occupy two bytes, int and float values occupy four bytes, double and long values occupy eight bytes, and pointers occupy four bytes. a) union u type ( double a[3]; int *b; char c[10] b) struct s1type float *d [2]; long e[4] char f[6] short *gi c) struct s2 type ( s1_type s; u type u [2]; int *h[3]; short...

  • Give the minimum size of each of the following C data structures, assuming that char values...

    Give the minimum size of each of the following C data structures, assuming that char values occupy byte, int and float values occupy four bytes, double values occupy eight bytes, and pointers occupy bytes. (a) char str[] = "Curly": (b) double *a[4][4]: (c) char *str[3] = {"Moe", "Larry", "Curly"}: (Include the space occupied by the string literals in your answer.) (d) union { int a: char b: float c[4]: }u: (e) struct { int a: char b: float c[4]: }s:...

  • 4. Consider the following declarations ; char c = ‘a’; byte b = 1; short s...

    4. Consider the following declarations ; char c = ‘a’; byte b = 1; short s = 2; int i = 3; long l = 4; float f = 5.0f; double d = 6.0; Indicate the value which is assigned to the LHS of the assignment statement in each of the following. a. i = b + 2 * s / 2 + i; b. i = (b + 2 * s) / (2 + i); c. i += (b...

  • Which of the following conversion factors, as written, would be used when converting a measurement in...

    Which of the following conversion factors, as written, would be used when converting a measurement in miles per hour to meters per second? Choose all that apply. (1.61 km / 1 mi) (60 s / 1 min) (60 min / 1 hr) (1000 m / 1 km) None of these converswion factors would be used.

  • S. Modułus operator can operate upon A. double B、 float C. char D. int E. C...

    S. Modułus operator can operate upon A. double B、 float C. char D. int E. C and D

  • Create a program (in C, not C++) called lab3.c that declares the following variables and displays...

    Create a program (in C, not C++) called lab3.c that declares the following variables and displays their values: Declare a character variable with value 'a', and display the character using printf with %c format. Then add a second printf that displays the character with a %d format. Declare a short int variable with a value set to the maximum value of a short int (the maximum value for whatever machine I happen to use to grade your assignment - so...

  • Create a UNIX makefile for the following C program: //convert.c char toUpper(char c){ if(c>='a' && c<='z')...

    Create a UNIX makefile for the following C program: //convert.c char toUpper(char c){ if(c>='a' && c<='z') return c-32; return c; } //converting sentance to upper void convertSentence(char *sentence){ int i=0; while(sentence[i]!='\0'){ //convert to upper for each character sentence[i] = toUpper(sentence[i]); i++; } } //converting all sentences into uppercase void convertAll(char **sentenceList, int numOfSentences){ int i=0; while(i<numOfSentences){ //calling convertsentence function to conver uppercase convertSentence(sentenceList[i]); i++; } } sentences.c #include<stdio.h> #include<stdlib.h> #include "convert.c" int main(){ //declaring character array char **mySentences; int noOfSentences;...

  • Given a database with the following tables: Students FirstName CHAR(20) | LastName CHAR(20) | StudentID INT...

    Given a database with the following tables: Students FirstName CHAR(20) | LastName CHAR(20) | StudentID INT | Major CHAR(20) | Degree CHAR(5) | Scholarship BOOLEAN | GPA FLOAT(3,2) | CreditsEarned INT | CreditsAttempted INT Classes ClassID INT | Title VARCHAR(50) | Description VARCHAR(255) | Credits SMALLINT Enrollments ClassID INT | StudentID INT C) Retrieve the First Name, Last Name, Major and StudentID of all students with a Scholarship:

  • Which of the following types can be safely compared using the == operator? A- string b-...

    Which of the following types can be safely compared using the == operator? A- string b- float c- double d- Char 2- What will be stored in variable i after the following statement is executed? int i = (int) Math.sqrt(5);

  • using c++ Write a C++ program which reads three values of types char, int, double and...

    using c++ Write a C++ program which reads three values of types char, int, double and string from the keyboard and primis, appropriately formatted, assigned values and variable types. For example, if letter, number, and real are variables of type char, int and double respectively, and if the values assigned to them using cin function are: a, 1, and 3.1415, then the output should be: a is a character 1 is an integen 3.1415 is a real number

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT