Why is it printing semi colon(;)? [closed] - c

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
The below program when executed is printing ';' as output. I am not understanding why. When I am changing the value of 'c' and 'i', it is sometimes adding those two and sometimes printing symbols like '=' and ';'
#include<stdio.h>
int main() {
char c='1';
int i=10;
printf("%c", c|i);
}

Because 49 | 10 = 59 and 59 is the ASCII code of ';'.

It is performing the bitwise OR operation of 49(00110001) OR 10(00001010), which is 00111011(59) , and returning the ascii value of 59, please visit the page http://ee.hawaii.edu/~tep/EE160/Book/chap4/subsection2.1.1.1.html

Related

Why this code is not working (if-statement) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Why "if" is not accepting the condition (both "x" and "n" are constants after all).
#include <stdio.h>
int main(){
int x,n;
scanf("%d %d",&x,&n)
if(x==(4n-3))
printf("%d",x);
return 0;
}
Compile and you get this:
error: expected ';' before 'if'
4 | scanf("%d %d",&x,&n)
| ^
| ;
The little ^ points out the exact location of the bug and tells you to write a semi colon there. Go to that location that the compiler points out and do as it says.
Then:
error: invalid suffix "n" on integer constant
5 | if(x==(4n-3))
This means that 4n is nonsense, it is not valid C. You need to write 4*n-3.
You aren't writing a math statement here
It should be if(x==(4*n-3))

Using %c in scanf and assigning the value to an int variable in C? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
int main()
{
int i= 0;
printf("i value is %d\n",i);
scanf("%c", &i); // I am giving an input of 255 here
printf("i after scan %d\n",i); // This prints 50. How???
return 0;
}
Can someone explain how does the printf statement give 50? I have a little-endian machine.
Your program won't even compile as I is undeclared. I am assuming that it is a typo. Since you are scanning %c it will read only one character which is 2 from 255. Now 2 has ascii code of 50 which is being printed.

how to separate a digit after semicolon using sscanf in c [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
//I wanted to separate last digit i.e."2" as an int from "hello.mp4;2" Here is the code:
int main()
{
char str[30];
int separate = 0;
strcpy( str, "hello.mp4;2" );
sscanf(str, "%*[^;]%d", &separate);
printf("%d\n",separate);
return 0;
}
and it is not woriking...
Change the sscanf to:
sscanf(str, "%*[^;];%d", &separate);
I.e., you need to match the semicolon ; after the string that excludes it. The portion in the square brackets matches the string that precedes the semicolon, leaving ;2. So you then need to match the semicolon ; before trying to match the 2.

why a[6] showing 344 value [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
#include<stdio.h>
int main()
{
int a[5]={1,2,3,4,5};
int i;
for(i=0;i<5;i++)
{
printf("%d",a[6]);
}
return 0;
}
Que : Why a[6] is showing 344 value, why not zero. Where this value came from ?
C does not check if you are going out of bound for an array. If you do so, it is undefined behavior, then you will get garbage value, in worst case, you can get a seg fault also.
Because a[6] is somewhere in memory which you don't know what holds.
In your case its 344.
Your compiler won't tell you that you are out of bound.

Output Of a While Loop [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
How many times the while loop is executed in the below prog if short int is of 2 bytes?
main()
{
int j = 1;
while(j <= 255);
{
printf("%d",j);
j++;
}
return 0;
}
i think it should be 255 times but its not correct. Can anyone tell me why?
You have a semicolon at the end of your while-line. The while loop, consisting of the statement ;, executes "infinitely" many times.

Resources