{"id":160305,"date":"2023-09-25T15:44:34","date_gmt":"2023-09-25T10:14:34","guid":{"rendered":"https:\/\/www.gkseries.com\/blog\/?p=160305"},"modified":"2023-09-25T15:44:34","modified_gmt":"2023-09-25T10:14:34","slug":"consider-the-following-c-code-assume-that-unsigned-long-int-type-length-is-64-bits","status":"publish","type":"post","link":"https:\/\/www.gkseries.com\/blog\/consider-the-following-c-code-assume-that-unsigned-long-int-type-length-is-64-bits\/","title":{"rendered":"Consider the following C code. Assume that unsigned long int type length is 64 bits"},"content":{"rendered":"\n<p>Q. Consider the following C code. Assume that unsigned long int type length is 64 bits.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/www.gkseries.com\/blog\/wp-content\/uploads\/2023\/09\/Screenshot-959.png\" alt=\"\" class=\"wp-image-160306\" style=\"width:528px;height:138px\" width=\"528\" height=\"138\" srcset=\"https:\/\/www.gkseries.com\/blog\/wp-content\/uploads\/2023\/09\/Screenshot-959.png 621w, https:\/\/www.gkseries.com\/blog\/wp-content\/uploads\/2023\/09\/Screenshot-959-300x78.png 300w\" sizes=\"(max-width: 528px) 100vw, 528px\" \/><\/figure>\n\n\n\n<p>The value returned when we call fun with the input 2<sup>40<\/sup> is<\/p>\n\n\n\n<p>(A) 4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (B) 5\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (C) 6\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (D) 40<\/p>\n\n\n\n<p>Ans: 5<\/p>\n\n\n\n<p>Sol:<\/p>\n\n\n\n<p>\/\/ n takes 2^40<br>unsigned long int fun(unsigned long int n) {<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/\/ initialized sum = 0\n    unsigned long int i, j = 0, sum = 0;\n\n    \/\/First it takes i = n = 2^40,\n    \/\/then it divides i by 2 and incremented once j\n    \/\/each time, that's will make makes j = 40,\n    for( i=n; i&gt;1; i=i\/2) j++;\n\n    \/\/Now the value of j = 40,\n    \/\/it divides j by 2 and incremented once sum\n    \/\/each time, that's will make makes sum = 5,\n    for( ; j&gt;1; j=j\/2) sum++;\n\n    \/\/returns sum = 5\n    return sum;<\/code><\/pre>\n\n\n\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Q. Consider the following C code. Assume that unsigned long int type length is 64 bits. The value returned when we call fun with the input 240 is (A) 4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (B) 5\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (C) 6\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (D) 40 Ans: 5 Sol: \/\/ n takes 2^40unsigned long int fun(unsigned long int n) { }<\/p>\n","protected":false},"author":419,"featured_media":160307,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5141],"tags":[5140],"class_list":["post-160305","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gate","tag-gate-questions"],"_links":{"self":[{"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/posts\/160305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/users\/419"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/comments?post=160305"}],"version-history":[{"count":1,"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/posts\/160305\/revisions"}],"predecessor-version":[{"id":160308,"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/posts\/160305\/revisions\/160308"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/media\/160307"}],"wp:attachment":[{"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/media?parent=160305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/categories?post=160305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gkseries.com\/blog\/wp-json\/wp\/v2\/tags?post=160305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}