FliQi Education App Download
प्रश्न-बैंक · C Language

Type Casting of C Language — प्रश्न और उत्तर

C Language · 29 जाँचे हुए (verified) प्रश्न

  • 29 जाँचे हुए प्रश्न
  • हिंदी + English

पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 19 के उत्तर और हल FliQi Question Bank app में।

भाषा
प्रश्न 1उत्तर + हल
निम्नलिखित एक्सप्रेशन का आउटपुट क्या होगा?
#include<stdio.h>
void main()
{
    int i = 9.0/2.0;
    printf("%d", i);
}
What will be the output of the following expression?
#include<stdio.h>
void main()
{
    int i = 9.0/2.0;
    printf("%d", i);
}
  1. A4.500000
  2. B4.000000
  3. C4
  4. DCompile time error

सही उत्तर / Answer: (C)

हल / Solution
9.0 और 2.0 दोनों दशमलव वाले हैं, इसलिए भाग double में होता है और मान 4.5 आता है। पर i पूर्णांक है, सो उसमें रखते ही दशमलव वाला भाग कट जाता है और 4 बचता है। %d से वही 4 छपता है। 4.500000 और 4.000000 के रूप %f से आते हैं, पूर्णांक चर से नहीं। कोड मान्य है, सो Compile time error भी ग़लत है।
Both 9.0 and 2.0 carry decimal points, so the division is done in double and the value is 4.5. But i is an integer, so the moment that value is stored the decimal part is cut away and 4 remains. With %d the same 4 is printed. The forms 4.500000 and 4.000000 come from %f, not from an integer variable. The code is valid, so Compile time error is wrong.
प्रश्न 2उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
void main()
{
    float f = 9/2;
    printf("%f", f);
}
What will be the output of the following program?
#include<stdio.h>
void main()
{
    float f = 9/2;
    printf("%f", f);
}
  1. A4.000000
  2. B4.500000
  3. C4.5
  4. D4

सही उत्तर / Answer: (A)

हल / Solution
9 और 2 दोनों पूर्णांक हैं, इसलिए भाग पूर्णांक में होता है और 4 निकलता है; दशमलव वाला भाग वहीं कट जाता है। f में 4.0 जाने पर %f छह दशमलव अंकों तक छापता है, सो आउटपुट 4.000000 है। 4.5 या 4.500000 तब मिलते जब कोई एक संख्या दशमलव वाली लिखी जाती, जैसे 9.0/2। केवल 4 का रूप %d का है।
Both 9 and 2 are integers, so the division is an integer division and gives 4; the decimal part is cut away there itself. With 4.0 in f, the %f format prints six digits after the decimal point, so the output is 4.000000. The values 4.5 and 4.500000 would come only if one number were written with a decimal point, as in 9.0/2, while plain 4 is what %d prints.
प्रश्न 3उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
void main()
{
    float f = (int)2/9.0;
}
variable f का मान ज्ञात कीजिए।
What will be the output of the following program?
#include<stdio.h>
void main()
{
    float f = (int)2/9.0;
}
Find the value of variable f.
  1. A0.222222
  2. B2.000000
  3. C0.000000
  4. D0

सही उत्तर / Answer: (A)

हल / Solution
cast की प्राथमिकता भाग से ऊँची है, इसलिए (int)2/9.0 का अर्थ है ((int)2)/9.0। cast सिर्फ़ 2 पर लगता है, जो पहले से int है। int 2 को double 9.0 से भाग देने पर C 2 को 2.0 में बदल देता है, इसलिए भाग असली होता है और 0.2222... आता है। f में यही जमा होता है, जो %f रूप में 0.222222 दिखता है। 0.000000 और 0 के लिए integer division चाहिए था, और 2.000000 में भाग ही नहीं हुआ।
The cast binds more tightly than division, so (int)2/9.0 means ((int)2)/9.0. The cast only affects 2, which is already an int. Dividing int 2 by the double 9.0 makes C convert 2 to 2.0, so the division is real and gives 0.2222... Stored in f, this is shown as 0.222222 in %f form. 0.000000 and 0 would need integer division, and 2.000000 ignores the division entirely.
प्रश्न 4उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
void main()
{
    float f = 2/9;
    printf("%f", f);
}
What will be the output of the following program?
#include<stdio.h>
void main()
{
    float f = 2/9;
    printf("%f", f);
}
  1. A0.222222
  2. B2.000000
  3. C0.000000
  4. D0

सही उत्तर / Answer: (C)

हल / Solution
यहाँ 2 और 9 दोनों पूर्णांक हैं, इसलिए भाग भी पूर्णांक में होता है और 2 बटा 9 का पूर्णांक भाग शून्य निकलता है। f में वही 0.0 जाता है, और %f छह दशमलव अंकों तक छापता है, सो आउटपुट 0.000000 है। 0.222222 तब मिलता जब कोई एक संख्या दशमलव वाली लिखी जाती, जैसे 2.0/9। केवल 0 का रूप %d का है, %f का नहीं।
Both 2 and 9 are integers here, so the division is an integer division, and the integer part of 2 divided by 9 is zero. That 0.0 goes into f, and %f prints six digits after the decimal point, so the output is 0.000000. The value 0.222222 would come only if one number were written with a decimal point, as in 2.0/9, while plain 0 is the form that %d would print.
प्रश्न 5उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
void main(){
    float f = 5/2.0;
    printf("%f", f);
}
What will be the output of the following program?
#include<stdio.h>
void main(){
    float f = 5/2.0;
    printf("%f", f);
}
  1. A2.5
  2. B2.500000
  3. C2.000000
  4. D2

सही उत्तर / Answer: (B)

हल / Solution
2.0 दशमलव वाला स्थिरांक है, इसलिए 5 भी पहले double में बदल जाता है और भाग का मान 2.5 आता है। f में वही 2.5 जाता है, और %f छह दशमलव अंकों तक छापता है, सो आउटपुट 2.500000 है। केवल 2.5 लिखना इस प्रारूप से मेल नहीं खाता। 2.000000 और 2 तब मिलते जब भाग पूर्णांक में होता, यानी 5/2 लिखा जाता।
The constant 2.0 carries a decimal point, so 5 is first changed into a double and the division gives 2.5. That same 2.5 goes into f, and %f prints the value up to six digits after the decimal point, so the output is 2.500000. Writing only 2.5 does not match this format. The forms 2.000000 and 2 would come if the division were an integer one, that is 5/2.
प्रश्न 6उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
void main(){
    int i = 5.0/2;
    printf("%d", i);
}
What will be the output of the following program?
#include<stdio.h>
void main(){
    int i = 5.0/2;
    printf("%d", i);
}
  1. A2.5
  2. B2.500000
  3. C2.000000
  4. D2

सही उत्तर / Answer: (D)

हल / Solution
5.0 दशमलव वाला स्थिरांक है, इसलिए भाग double में होता है और उसका मान 2.5 निकलता है। पर i पूर्णांक है, सो उसमें रखते ही दशमलव वाला भाग कट जाता है और 2 बचता है। %d से वही 2 छपता है। 2.5 और 2.500000 तब मिलते जब चर ख़ुद float या double होता, और 2.000000 का रूप भी %f का ही है।
Since 5.0 carries a decimal point, the division is done in double and its value comes out as 2.5. But i is an integer, so the moment the value is stored the decimal part is cut away and 2 remains. With %d that same 2 is printed. The forms 2.5 and 2.500000 would appear only if the variable itself were a float or double, and 2.000000 also belongs to %f.
प्रश्न 7उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
void main()
{
    int i = 5/2;
    printf("%d", i);
}
What will be the output of the following program?
#include<stdio.h>
void main()
{
    int i = 5/2;
    printf("%d", i);
}
  1. A2.5
  2. B2
  3. C2.000000
  4. DCompile time error

सही उत्तर / Answer: (B)

हल / Solution
यहाँ 5 और 2 दोनों पूर्णांक हैं, इसलिए भाग भी पूर्णांक में होता है और दशमलव वाला भाग वहीं कट जाता है — i के पास 2 बचता है। %d पूर्णांक को जैसा है वैसा छापता है, सो आउटपुट 2 है। 2.5 तब मिलता जब कोई एक संख्या दशमलव वाली लिखी जाती, जैसे 5.0/2, और 2.000000 का रूप %f का है। कोड मान्य है, सो त्रुटि भी नहीं।
Both 5 and 2 are integers here, so the division is an integer division and the decimal part is cut away at once; i holds 2. The %d format prints an integer as it is, so the output is 2. The value 2.5 would come only if one of the numbers were written with a decimal point, as in 5.0/2, and the form 2.000000 belongs to %f. The code is valid, so there is no error.
प्रश्न 8उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
void main(){
    float f = (float)5/2;
    printf("%f", f);
}
What will be the output of the following program?
#include<stdio.h>
void main(){
    float f = (float)5/2;
    printf("%f", f);
}
  1. A2.5
  2. B2.500000
  3. C2.000000
  4. DCompile time error

सही उत्तर / Answer: (B)

हल / Solution
(float) लिखने से 5 पहले float बन जाता है, इसलिए भाग भी float में होता है और f के पास 2.5 आता है। %f मान को छह दशमलव अंकों तक छापता है, सो आउटपुट 2.500000 है — केवल 2.5 लिखना इस प्रारूप से मेल नहीं खाता। 2.000000 तब मिलता जब दोनों संख्याएँ पूर्णांक रहतीं और पूर्णांक भाग होता। कोड मान्य है, सो Compile time error भी ग़लत है।
The cast (float) turns 5 into a float first, so the division is done in float and f receives 2.5. The %f format prints the value up to six digits after the decimal point, so the output is 2.500000; writing only 2.5 does not match that format. The value 2.000000 would come if both numbers stayed integers. The code is valid, so Compile time error is wrong.
प्रश्न 9उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
void main(){
    float f = 5/2;
}
variable f का मान ज्ञात कीजिए।
What will be the output of the following program?
#include<stdio.h>
void main(){
    float f = 5/2;
}
Find the value of variable f.
  1. A2.5
  2. B2.500000
  3. C2.000000
  4. Dकंपाइल टाइम त्रुटिCompile time error

सही उत्तर / Answer: (C)

हल / Solution
5 और 2 दोनों int हैं, इसलिए 5/2 integer division है और उत्तर 2 आता है; .5 रूपांतरण से पहले ही फेंक दिया जाता है। इसके बाद int 2 को float में बदलकर f में रखा जाता है। इसलिए f में 2.0 है, जो %f रूप में 2.000000 दिखता है। विकल्प 1 और 2 असली भाग मानकर चलते हैं, जिसके लिए 5.0 या cast चाहिए था। कोड सही है, इसलिए compile error भी नहीं है।
Both 5 and 2 are int constants, so 5/2 is integer division and gives 2; the .5 is thrown away before any conversion happens. Only then is the int 2 converted to float for the assignment, so f holds 2.0, shown in the usual %f form as 2.000000. Options 1 and 2 assume real division, which would need 5.0 or a cast. The code is valid, so there is no compile error.
प्रश्न 10उत्तर + हल
इस C प्रोग्राम का आउटपुट क्या है?
#include<stdio.h>
void main()
{
    double d = 'A';
    printf("%f", d);
}
What is the output of this C program code?
#include<stdio.h>
void main()
{
    double d = 'A';
    printf("%f", d);
}
  1. A65.000000
  2. BA
  3. C97.000000
  4. DCompile time error

सही उत्तर / Answer: (A)

हल / Solution
'A' एक वर्ण स्थिरांक है और ASCII में उसका मान 65 है। उसे double में रखते ही मान 65.0 हो जाता है, और %f छह दशमलव अंकों तक छापता है, इसलिए आउटपुट 65.000000 मिलता है। अक्षर A तब दिखता जब %c लगाया जाता; 97 तो छोटे a का कोड है, बड़े A का नहीं। सीधे उद्धरण वाला कोड मान्य है, सो Compile time error भी ग़लत है।
Here 'A' is a character constant and its ASCII value is 65. Storing it in a double makes the value 65.0, and %f prints six digits after the decimal point, so the output is 65.000000. The letter A would appear only if %c were used, and 97 is the code of small a, not of capital A. With straight quotes the code is valid, so Compile time error is wrong.
आगे के 19 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 12उत्तर app में
इस C प्रोग्राम कोड का आउटपुट क्या है?
#include<stdio.h>
void main()
{
    int i = 98.17;
}
variable i का मान ज्ञात कीजिए।
What is the output of this C program code?
#include<stdio.h>
void main()
{
    int i = 98.17;
}
Find the value of variable i.
  1. A98.17
  2. B98
  3. C98.170000
  4. Dकंपाइल टाइम त्रुटिCompile time error
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 14उत्तर app में
टाइपकास्टिंग (typecasting) ख़तरनाक क्यों हो सकती है?
Why can typecasting be dangerous?
  1. ASome conversions are not defined, such as char to int.
  2. BYou might permanently change the value of the variable.
  3. CYou might temporarily lose part of the data - such as truncating a float when typecasting to an int.
  4. DThere are no dangers.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में
इम्प्लिसिट टाइप कनवर्ज़न में, यदि एक्सप्रेशन में long double, float, double, int टाइप के ऑपरेंड मौजूद हैं, तो संबंधित ऑपरेंड भी किसमें परिवर्तित हो जाएंगे?
In implicit type conversion, if an operand of type long double, float, double, int is present in the expression, then the corresponding operands will also be converted to
  1. Adouble
  2. Blong double
  3. Cint
  4. Dfloat
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 20उत्तर app में
यदि किसी एक्सप्रेशन में दिए गए operands int, long int, float तथा unsigned long int टाइप के हों, तो आउटपुट किस टाइप का आएगा?
If the operands given in an expression are of type int, long int, float and unsigned long int, then what type of output will come?
  1. Aint
  2. Bunsigned long int
  3. Cfloat
  4. Dlong int
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 21उत्तर app में
निम्नलिखित कोड के लिए आउटपुट क्या होगा?
#include<stdio.h>
int main()
{
double x = 1.2;
int sum = (int)x + 1;
printf("sum = %d", sum);
return 0;
}
What will be the output of the following code?
#include<stdio.h>
int main()
{
double x = 1.2;
int sum = (int)x + 1;
printf("sum = %d", sum);
return 0;
}
  1. Asum = 2
  2. Bsum = 1
  3. Csum = 2.2
  4. Dsum = 2.200000
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 22उत्तर app में
निम्नलिखित कोड के लिए आउटपुट क्या होगा?
#include<stdio.h>
int main()
{
int x = 10;
char y = 'a';
x = x + y;
float z = x + 1.0;
printf("x = %d, z = %f", x, z);
return 0;
}
What will be the output of the following code?
#include<stdio.h>
int main()
{
int x = 10;
char y = 'a';
x = x + y;
float z = x + 1.0;
printf("x = %d, z = %f", x, z);
return 0;
}
  1. Ax = 107, z = 108
  2. Bx = 107.000000, z = 108.000000
  3. Cx = 107, z = 108.000000
  4. Dx = 108, z = 108.000000
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 23उत्तर app में
निम्नलिखित कोड किसका उदाहरण है?
double da = 4.5;
double db = 4.6;
double dc = 4.9;
 
//explicitly defined by user
int result = (int)da + (int)db + (int)dc;
printf("result = %d", result);
The following code is an example of?
double da = 4.5;
double db = 4.6;
double dc = 4.9;
 
//explicitly defined by user
int result = (int)da + (int)db + (int)dc;
printf("result = %d", result);
  1. AImplicit Type Conversion
  2. BExplicit Type Conversion
  3. CError
  4. DCannot Say
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 24उत्तर app में
किस रूपांतरण को स्वचालित (automatic) प्रकार का रूपांतरण भी कहा जाता है?
Which conversion is also called Automatic Type Conversion?
  1. Aनिहित प्रकार रूपांतरण (Implicit Type Conversion)Implicit Type Conversion
  2. Bस्पष्ट प्रकार रूपांतरण (Explicit Type Conversion)Explicit Type Conversion
  3. CA और B दोनोंBoth A and B
  4. Dइनमें से कोई नहींNone of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 27उत्तर app में
निम्नलिखित में से कौन-सी टाइपकास्टिंग C भाषा द्वारा स्वीकार की जाती है?
Which of the following typecasting is accepted by C language?
  1. AWidening रूपांतरणWidening Conversions
  2. BNarrowing रूपांतरणNarrowing Conversions
  3. CWidening और Narrowing दोनों रूपांतरणWidening & Narrowing Conversions
  4. Dइनमें से कोई नहींNone of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
Type Casting of C Language के सभी 29 प्रश्न — उत्तर, हल और अभ्यास

FliQi Question Bank app में topic-वार अभ्यास, कठिनाई-स्तर और आपकी प्रगति।

  • पहला test मुफ़्त
  • हिंदी + English
  • जाँचे हुए उत्तर और हल

यह topic किन परीक्षाओं में आता है

C Language के दूसरे topics

सभी topics