syntax - What is the meaning of '==' in C? - Stack Overflow
what does "|=" operator mean in C? - Stack Overflow
What does it mean, in the text messages, 'c' is in the end of the text? For example, how are you? c what does this "c" mean?
Could someone explain the use of the asterisk * in C and how it is used?
Videos
Like, spanish Si, for yet?
Just curious
== is a test for equality. = is an assignment.
Any good C book should cover this (fairly early on in the book I would imagine).
For example:
int i = 3; // sets i to 3.
if (i == 3) printf("i is 3\n"); // prints it.
Just watch out for the heinous:
if (i = 4) { }
which is valid C and frequently catches people out. This actually assigns 4 to the variable i and uses that as the truth value in the if statement. This leads a lot of people to use the uglier but safer:
if (4 == i) {}
which, if you accidentally use = instead of ==, is a compile-time error rather than something that will bite you on the backside while your program is running :-)
The logical-or operator is two vertical bar characters, one after the other, not a single character. Here it is lined up with a logical-and, and a variable called b4:
||
&&
b4
No magic there.
a == b is a test if a and b are equal.
a = b is called an assignment, which means to set the variable a to having the same value as b.
(You type | with Shift-\ in the US keyboard layout.)
It works like the | + the = operator, in a similar way as += works.
It is equivalent as
a = a|b;
I suggest you to read this article about operators: http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Bitwise_operators Ans this one about bitwise operation http://en.wikipedia.org/wiki/Bitwise_operation
Following the pattern of, for example, +=:
a |= b;
// Means the same thing as:
a = a | b;
That is, any bits that are set in either a or b shall be set in a, and those set in neither shall not be set in a.
I am currently working on an assignment in C where we are required to make a stack by simply using pointers.
I know the line: int *ptr = &val; declares ptr to be a "pointer to"(which is my interpretation of what asterisk * means in C) the "address of" the integer variable val.
When I want to create a double pointer, or a pointer to a pointer, I do so like:
int **ptr_ptr = &ptr; By setting ptr_ptr to a "pointer to" the address of pointer ptr.
When we use the asterisk anywhere other than in a declaration, it is usually referred to as dereferencing that pointer (I think), and grabbing the value that the pointer actually points to. This goes against my intuition that an asterisk means "pointer to".
Could anybody explain the proper meaning of the asterisk in C? Is it just that it means different things depending on how it is used (i.e. in a declaration versus anywhere else)?
Thanks!
for(i=0;i<lim-1&&(c=getchar())!=EOF&&c!='\n';i++)why do we usec!='\n'
We use c!='\n' to stop scanning input characters when user enters a \n (newline) character or in other words,when user hits the enter key.
why have we used
s[i]='\0'in andi++;statement inif(c=='\n')condition
i++is used to increase the index value of the array/string for one last time to accomadate the terminating'\0'null character.s[i]='\0'is used to terminate\end the string with a null character. This is essential for marking the end of the string and printing a string within bounds (upto'\0'character)
The getline function is wrong.
This is the corrected readable version:
int getline(char s[], int lim)
{
int c,i;
for(i=0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; i++)
{
s[i]=c;
if(c=='\n')
{
s[i]='\n';
i++;
}
}
s[i]='\0';
return i;
}