Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,938 questions

51,875 answers

573 users

What it the result of right shift of a negative integer in C

1 Answer

0 votes
#include <stdio.h>

int main(void) 
{
    int n = -1;

    for (int i = 1; i <= 10; i++ )
    {
        int result = n >> 1;
        printf("%d\n", result);
    }
    
    return 0;
}

// C doesn't guarantee right-shift a negative signed number
    
/*
run:
 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

*/

 



answered Aug 28, 2017 by avibootz

Related questions

1 answer 157 views
1 answer 120 views
120 views asked Jun 27, 2024 by avibootz
1 answer 103 views
1 answer 153 views
1 answer 135 views
...