GATE | GATE-CS-2003 | Question 74

The following program fragment is written in a programming language that allows variables and does not allow nested declarations of functions.

 global int i = 100, j = 5; void P(x) {     int i = 10;     print(x + 10);     i = 200;     j = 20;     print(x); } main() {     P(i + j); }

If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program are :
(A) 115, 220
(B) 25, 220
(C) 25, 15
(D) 115, 105

Explanation:

 global int i = 100, j = 5; void P(x) // x = i + j {     int i = 10;     print(x + 10);// print (100+5+10) = 115     i = 200;     j = 20;     print(x); // print (200+20) = 220.      // i and j would be changed as they are global variables } main() {     P(i + j); }

Thus, A is the correct option as 115 and 220 are printed.

Please comment below if you find anything wrong in the above post.

Quiz of this Question

My Personal Notes arrow_drop_up

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.
{"ft_lang_label":"__label__en","ft_lang_prob":0.72847927,"math_prob":0.98055255,"size":1713,"snap":"2019-43-2019-47","text_gpt3_token_len":602,"char_repetition_ratio":0.26155648,"word_repetition_ratio":0.3871951,"special_character_ratio":0.41447753,"punctuation_ratio":0.092307694,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9913188,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-10-16T09:11:51Z\",\"WARC-Record-ID\":\"<urn:uuid:a1f901f7-b1f6-4d2e-a090-a00ac84d107a>\",\"Content-Length\":\"88424\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2de9263f-c70a-410f-88c7-307663af23b6>\",\"WARC-Concurrent-To\":\"<urn:uuid:509d6c49-aaa0-4048-95dc-8c70e976cf79>\",\"WARC-IP-Address\":\"23.221.72.19\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/gate-gate-cs-2003-question-74/\",\"WARC-Payload-Digest\":\"sha1:LM3FI5Q2F6FOS5RK7K6QU3CIPH5CTRE2\",\"WARC-Block-Digest\":\"sha1:Q5FMPCVCVNY3JGRCLAC7DDXQOBB6OY3V\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-43/CC-MAIN-2019-43_segments_1570986666959.47_warc_CC-MAIN-20191016090425-20191016113925-00293.warc.gz\"}"}