Understanding the use of * operator in C

Most of the beginner struggle with the symbol *. We are here to learn about this notation in a very simple way.
 

The symbol * is used mainly in three places:
1. In an arithmetics expression
2. During the declaration of a pointer variable
3.In the expressions involving pointer variables.
 

Hence, there are three names for this symbol in C:

1. Multiplication Operator:
If the symbol * is used in arithmetic expressions (between two normal variables ), we call it a Multiplication Operator.
Here is a simple code example:
int main() {
    int a,b,c;
    a = 10;
    b = 5;
    c = a*b;  // Here * is a Multiplication operator
    printf("value of c = %d",c);
    return 0;
}
Output: 
value of c = 50

2. Indirection Operator
If the symbol * is used during the declaration of a pointer variable then we call it an Indirection Operator. The symbol * directs the compiler during the lexical analysis phase that the variable name after this is for a pointer variable, not for a normal variable.

int main() {
    int a,b,c;
    int *p;  // Here * is an Indirection operator
    p = &c;
    a = 10;
    b = 5;
    c = a*b;  // Here * is a Multiplication operator
    printf("value of c = %d",c);
    return 0;
}
Output:
value of c = 50

3. Value at Operator
If the symbol * is used in the expressions before pointer variables then we call it a Value at Operator.

int main() {
    int a,b,c;
    int *p;  // Here * is an Indirection operator
    p = &c;
    a = 10;
    b = 5;
    c = a*b;  // Here * is a Multiplication operator
    printf("value of c = %d",*p); // Here * is a Value at operator
    return 0;
}
Output:
value of c = 50
 

Explanation of the above code:
p is a pointer variable that is holding the address of an integer variable c. Let's say the address of c is "1001".
Hence the meaning of the expression *p will be Value at p = Value at 1001 = 50 (i.e, the value of variable c)

Here is another simple code example:

int main() {
    int a,b,c,d;
    int *p;  // Here * is an Indirection operator
    p = &c;
    a = 10;
    b = 5;
    c = 2;
    d = *p+a*b  // Here first * is Value at operator and second * is a Multiplication operator
    printf("value of d = %d", d);
    return 0;
}
Output:
value of d = 52
 

In the above code, p is a pointer variable that is holding the address of an integer variable c. Let's say the address of c is "1001". Hence the meaning of the expression *p+a*b will be as below:

d = *p+a*b
d = value at p + a multiplication b
d = value at 1001 + 10 multiplication 5
d = 2 + 50
d = 52

_______________________________________________________
How about putting more than one * together?
Well, here is the final and a little complex example to understand this.

int main() {
    int a,b,c,d;
    int *p,*q;  // Here * is an Indirection operator
    int **r;  // Here ** is the indrection operator for declaration of a double pointer (pointer to pointer)
    p = &c;
    q = &a;
    r = &p;
    a = 10;
    b = 5;
    c = 2;
    d = **r + *q * b;
    printf("value of d = %d", d);
    return 0;
}
Output:

value of d = 52
 

Explanation of the above code:
Let's assume addresses of variables a and c are 1001 and 2002 respectively and the address of pointer variable p is 3003. We can solve the below expression as:

d = **r + *q * b
d = value at (value at r)) + value at (q) multiplication (b)

d = value at (value at 3003) + value at (1001) multiplication b

d = value at (2002) + 10 multiplication 5

d = 2 + 50

d = 52

0Comment
GATE-2017 set 1 -22

Consider the first-order logic sentence F: ∀x(∃yR(x,y)). Assuming non-empty logical domains, which of the sentences below are implied by F?

I.      ∃y(∃xR(x,y))
II.     ∃y(∀xR(x,y))
III.   ∀y(∃xR(x,y))
IV. ¬∃x(∀y¬R(x,y))

 

A.  IV only

B.  I and IV only

C.  II only

D.  II and III only

Option B is correct.

let R(x,y) means x likes y.

let there are some people named:  Ambikesh, Alankrita, Sunny, Harshita, Vatsala.

 

F: ∀x(∃yR(x,y)) means : Everyone likes someone.   

So the following cases may be possible.                       Example  :  Ambikesh likes Alankrita.

                                                                                                                               : Alankrita likes Sunny

                                                                                                                                : Sunny likes Harshita   

                                                                                                                               : Harshita likes Ambikesh

                                                                                                                               : Vatsala likes Sunny

 

I.      ∃y(∃x R(x,y)):   Someone is liked by someone.  it is a subset of the above example and a subset is always implied by its superset.

 

II.     ∃y(∀xR(x,y)) :  Someone is liked by everyone. False: There is no one you can find who is liked by everyone.

 

III.   ∀y(∃xR(x,y)) :  Everybody is liked by someone:   False:  Vatsala is not liked by anyone.

 

IV.    ¬∃x(∀y¬R(x,y))   After propagating the negation, It can be written as:   ∀x(∃yR(x,y))

 

So option I and IV are correct.

0Comment
Gate IT 2007
Difficulty Level:  intermediate
Total Questions: 85
0Comment
Gate CSE 2006
Difficulty Level:  intermediate
Total Questions: 85
0Comment
Gate CSE 2002
Difficulty Level:  intermediate
Total Questions: 50
0Comment
Introduction to Hamming Code and Parity Bits

 

  •  To detect d bit error we need d+1  bits. 
  • To Correct d bit error, we need 2d+1 bits.

Hamming code:

A Hamming code detects and corrects only one-bit error.

Parity bits: Along with message bits sender sends some extra bits which are helpful in error detection and correction. Those extra added bits are called Parity bits

There are two types of parity bits in Hamming code:

1. Even parity: If the total number of 1's including parity bits in a message is even, then that is called even parity. 

Example: let a sender sends a packet (message bits + parity bits) = 1010101000, Number of 1's is 4, So it is even parity.

2. Odd parity: If the total number of 1's including parity bits in a message is odd, then that is called odd parity. 

Example: let a sender sends a packet (message bits + parity bits) = 110010001001, Number of 1's is 5, So it is odd parity.

 

Deciding Parity Bits:-

let me ask you some questions:

  1. How many pairs bits are added if the total number of bits in a message is  m ?
  2. How the Receiver will know whether the error has happened or not?

Calculating Number of  parity bits:

let the number of message bits = m and

number of the parity bits            = p

then p should be satisfying g this easy condition:  \large {\color{Red} 2^p\geq m+p +1}

Example :

1. let the number of message bits = 4

Then

1. The number of parity bits \large p :

            \large 2^p= m+p +1

            \large 2^p= 4+p +1

            \large 2^p= 5+p 

Now the minimum value of \large p satisfying this equation is 3 So the total number of parity bits = \large 3

2. Total number of bits in Message(to be send)  =   parity bits + original message bits

                                                                                                     =      \large 3+4 =7

 

2. let's take  another example:

number of message bits = 7

So parity bit (p) = ???

       \large 2^p= m+p +1

      \large 2^p= 7+1+p= 8+p 

if \large p=4 

     \large 2^4\geqslant 8+4= 16\geq 12 

Yes, the equation is satisfied.

So the number of parity bit (p) =\large 4

Total number of bits in Message(to be send)  =   parity bits + original message bits

                                                                                                =    \large 11   

 

Each parity bits have some special functionality depending on their location and parity bits are added only  at location  \large 2^n:  where n= 0,1,2,3..........n

It means we can have parity bits at location 1, 2, 4, 8, 16.......

depending on the location of parity bits  we can write them like this

\large p_{1} = parity bit at location 1

\large p_{2} = parity bit at location 2

\large p_{4}= parity bit at location 4 ..... 

Remember \large p_{4} doesn't mean that it is number 4 So, it means it is used at location  number 4.

For example : let's say our message bit is like 

\large M= m_{1}m_{2}m_{3}m_{4} there are 4 bits so we need 3 parity bits and they are: \large p_{1}, p_{2}, p_{4}

So a total of 7 bits are needed to be sent: 

Location:      1       2      3       4      5      6       7  

Bits:                {\color{Red} p_{1}}    {\color{Red} p_{2}}   {\color{Blue} m_{1}}  {\color{Red} p_{4}}    {\color{Blue} m_{2}}   {\color{Blue} m_{3}}    {\color{Blue} m_{4}}

Each parity bit is going to take care of another bit depending on the location of the parity bit. Example:

{\color{Red} p_{1}=} {\color{Blue} 1,3,5,7,9,11}

{\color{Red} p_{2}=} {\color{Blue} 2,3,6,7,10,11....}

{\color{Red} p_{4}=} {\color{Blue} 4,5,6,7,12,13.14.15....} and so on.

How to remember this:

let's talk about {\color{Red} p_{4}=} {\color{Blue} 4,5,6,7,12,13.14.15....} {\color{Red} p_{4}} has a subtext 4 that's why it starts with 4 and read four continuous value 4,5,6,7 then it makes a gap for four number(8,9,10,11). Now it will read the next four value 12,13,14,15 and again a gap of four continuous numbers(16,17, 18, 19) and so on...

Now we are done with basics. Let's move forward to implement all this stuffs.

 

 

 

 

0Comment
Check function is functionally complete or not

 f(A,B,C)=A'+BC'   check functionally complete or not

 

Answer

If we are able to derive  (AND,NOT) or  (OR,NOT) then it is functionally complete otherwise not

For completement(Not) :

 Do like this it is easy to find compliment

          put f(A,A,A) orF(B,B,B) or f(C,C,C)

       then we get completement, let we put f(A,A,A )in given function then we get 

         f(A,A,A)=A'.......(We got Completementi.e NOT)

        Now try for 'OR' or 'AND'

        Let check for 'OR' i.e f(A,B,C)=A+B

            so put f( f(A,A,A),B,F(B,B,B))  in given function  SO,

         f( f(A,A,A),B,F(B,B,B) )=A+B.....( since we know  f(A,A,A)=A'  F(B,B,B)=B')

         therefore we are able to get  'NOT' and 'OR'  so  this function is functionally complete

Note :If the given expression is not having any complement variable then it is not possible to get any complement(i.e NOT).Then directly we can say to that function is not functionally complete.

Example : f(A,B,C)=AB+BC+CA in this example we have no complemented variable then by looking directly to function we can say it is not  functionally complete.

 

 

 

1Comment
Functionally completeness

A set of operation is said to be functionally complete or universal if and only every switching function can be expressed by means of operation in it

  • The set \left \{+,.,- \right \} is clearly functionally complete.
  • The set \left \{+,,- \right \} or \left \{ .,- \right \} also functionally complete.

Note : A set is said to be functionally complete if we can derive a set which is already functionally complete

0Comment
Number System Quiz
Difficulty Level:  intermediate
Total Questions: 5
0Comment

Pages