Github Link:
#BCA #PUCHD #coding #bca1 #bcaprograms #cprograms #important #cprogramming
Github Link:
#BCA #PUCHD #coding #bca1 #bcaprograms #cprograms #important #cprogramming
Q:: C programming:::
What will be the output?
void main()
{
static int i=0;
if(++i)
{
printf("℅d",i);
main();
}
}
(A) 1,1,1,1...
(B) 0,0,0,0...
(C) 1,2,3,4...
(D) None of these
Answer:: (D)
Explanation:
It will go upto range of integer here we are considering int takes 2 bytes.
1,2,3,4 ...32766,32767,-32768,-32767...-2,-1
Q::What will be the output::
void main()
{
static char ch=1;
while (ch++)
{
printf("℅d",ch);
}
}
(A) error
(B) It will run infinite time
(C) Prints 2,3,4...127 ,-128-127-126...-1
(D) Prints 2,3,4...127, -128-127-126...-1,0
Answer:: (D)
Explanation::
Firstly ch= 1 so , control enter the while loop and ch is incremented by 1
and ch =2 gets printed
going on this way the value of ch will become 127 and again it will be incremented by 1 which will make it -127 which is again true in C Language then -126,-125... -1,0 also get printed . Before printing value of ch is always incremented by 1.
The following statement ::
printf("%d",++5);
will print:
a)5 b) 6 c) error d)garbage
Answer:: (C)
Explanation::
The statement will be expanded like
5=5+1;
i.e. a constant on left side of expression which is not allowed in 'C' hence it will generate error.
Q:: What will the output of following?
for(i=0;i<10;++i)
printf("%d",i&1);
(a)0101010101 (b)0111111111
(c)0000000000 (d)1111111111
Answer :: (A)
Explanation::
Binary representation of 1 is 0000000000000001 in 16 bit
In first iteration i=0
i=0000000000000000
1=0000000000000001
i&1=0000000000000000=(0)
In second iteration i=1
i=0000000000000001
1=0000000000000001
i&1=0000000000000001=(1)
In third iteration i=2
i=0000000000000000
1=0000000000000010
i&1=0000000000000000=(0)
In fourth iteration i=3
i=0000000000000011
1=0000000000000001
i&1=0000000000000001=(1)
So it will produce 0 when 'i' is even
and '1' if 'i' is odd
Output will be 0101010101
Q:: What will be the output for following loop :->
for(putchar('c');putchar('a');putchar('r'))
{
putchar('t');
}
(a)error (B)cartrt
(C)catrat (D)catratratrat...
As per for loop execute
for(1. Initialization;2.Condition Check; 3. Iteration Variable change)
Now as per given question
1. Initialization is given by putchar('c)
2. Condition Check by putchar('a')
3. Iteration by putchar('r')
In for loop statement putchar('t') is there
Also sequence is
1. Initialization only once putchar('c')
2. Condition check putchar('a')
3. Statement putchar('t')
4. Iteration putchar('r')
2. putchar('a')
3. putchar('t')
4. putchar('r')
2. putchar('a')
3. putchar('t')
.
.
.
and so on so result will catratratrat.... Infinite times
🚀 CODING ACCELERATION PROGRAM (90 DAYS) Build Strong Foundations Learn to Think Like a Programmer Get Placement Ready 💡 Learn C Progra...