Get Off-Campus Placement Jobs Info !!!
Programs asked in Mettl Coding Round
Click To Practce List of Programs asked in Nagarro !!!

# Commvault Written Test Qs.(C++ Programming) :: Functions - Discussion

8 / 40

What is the output of the C++ program?

## #include <iostream> using namespace std; void fun(int a, int b, int &c,int &d) { c += a + b; d += a - b; } int main () { int vl = 5, v2 = 10, v3 = 2, v4 = 3; fun(vl, v2, v3, v4); cout << v3 << " "<< v4 ; return 0; }

A15 -5

B2 3

C17 -2

DNone of the above

Show Explanation

The question has some problems. The main function must return int instead of void. otherwise the compiler throws "â€˜::mainâ€™ must return â€˜intâ€™ " error. And '#include <iostream>' should be included to use IO functions.

Explanation:

By associativity of operators, the expressions c += a + b; and d += a - b; will be evaluated from right to left and remember the arguments c and d pass by reference.

a = 5, b= 10, c= 2, d= 3;

So  c += 15 and c becomes 17, d += -5 and d becomes -2.

#### Asked In :: Commvault Societe Generale

Rate This: +0 -0 To Reading List
{"ft_lang_label":"__label__en","ft_lang_prob":0.67965174,"math_prob":0.94253445,"size":1365,"snap":"2020-34-2020-40","text_gpt3_token_len":453,"char_repetition_ratio":0.08817046,"word_repetition_ratio":0.38434163,"special_character_ratio":0.378022,"punctuation_ratio":0.19344263,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97171986,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-10-02T00:00:58Z\",\"WARC-Record-ID\":\"<urn:uuid:47b55591-5d32-4b0a-919d-21375590a32f>\",\"Content-Length\":\"111447\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5170641e-350c-4140-9b18-db6561fc5467>\",\"WARC-Concurrent-To\":\"<urn:uuid:3e692ef9-1262-4fd9-b027-36156a565e4c>\",\"WARC-IP-Address\":\"18.232.245.187\",\"WARC-Target-URI\":\"https://q4interview.com/commvault/written-round/include-using-namespace-stdvoid-funint-a-int-b-int-cint-dc/1490\",\"WARC-Payload-Digest\":\"sha1:QMJU5OFUTS3ZMHZHACJL3MJLVZSQVRKZ\",\"WARC-Block-Digest\":\"sha1:IESKIKBM5LFQDH6ZRAS3W57ZZ6GT64RN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600402132335.99_warc_CC-MAIN-20201001210429-20201002000429-00437.warc.gz\"}"}