The code will print foo. This is because of the if statement in the function.
if(foo=1) here the statement is not making comparison but is doing assignment, assigning value 1 to foo. the statement will be aways true and if statement will be executed.
To solve this, make if statement as:
if(foo == 1)
Problem 4 (25 points). What will the following code print? Why? Identify the line where the...
C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...
b) [3 points] What will be the output of the following code? Explain your answer. enum direction {UP, DOWN, LEFT, RIGHT); void foo (enum direction* a, enum direction b) enum direction * c = a; b = RIGHT; *c = LEFT; *c = RIGHT ; int main (void) enum direction d1 = enum direction d2 printf ( "d1 %d, d2 foo (&d1, d2); printf("d1- %d, d2 return 0 UP; DOWN; = %d\n", d1, d2); %d\n", d1, d2);
What number does each line of code print out? Briefly explain why. printf("%u\n",(unsigned char)(-2)); printf("%d\n",(unsigned char)(-2)); printf("%u\n",(uint16_t)(-2)); printf("%d\n",(uint16_t)(-2)); printf("%u\n",(unsigned int)(-2)); printf("%d\n",(unsigned int)(-2));
5.1 Automatic properties Choose One 4 points Given the following code where does the value assigned to the automatic property get stored? ?# 1 class Foo 2 3 string_name; 4 5 string Bar (get;set;) 7 8 10 static void Main() 12 13 object.Bar"Hello"; Foo object new Foo(); 14 0 In the-name field O in a hidden field created by the Property O The value is not stored O You have to create a field to hold the value
c++ only. Please follow directions. What does the following program print and why? Comment each line of code to explain what it is doing. #include <iostream> using namespace std; int main() { int track[ ] = { 10, 20, 30, 40 }; int * ptr; ptr = track; track[1] += 30; cout << * ptr << " "; *ptr -= 10; ptr++; cout << * ptr << " "; ptr += 2; cout << * ptr << " "; cout...
What is the output of the following code segment and why? int main(void) { // Find the output of the following and explain it: char name[] = "Hello"; name[2] = '\0'; printf("%s\n", name); return 0; } why answer is he?
10. Does the following code compile? Does it run? Is there any problem with the code? If yes, how do you fix it? 1. #include < iostream > 2. using namespace std; 4 class Computer int Id; 7. public: Computer(int id) this -Id- id; ) void process() cout << "Computer::process()"; 9 10. H; 12. class Employee 13. 14. 15. public: 16 Computer* c; Employee )cnew Computer (123); 17.Employee() C 18. 19. 20 21. 22. ^; 23. 24. int main(){ 25....
in C language please! 9. 14 points Show what the following C code will print. const int MAX_I_COUNT = 4; const int MAX_J_COUNT = 15; int i, j; for( i = 1; i <MAX_I_COUNT; i++) { for(j = 2; j <MAX_J_COUNT; j += 4 ) printf("%d", j + i); puts("\n-----" ); puts( "I'm Done!" ); 10. 14 points What would be printed? int bean = 5, cheese = 3; int *p = &bean; *p += bean; ++cheese; *p += cheese;...
Consider the following C codes to compute the gcd of two integers. /// code 1 #include <stdio.h> int gcd(int a, int b) { while (a != b) { if (a > b) a = a - b; else b = b - a; } return a; } /// code 2 #include <stdio.h> int getint() { int i; scanf("%d", &i); return i; } void putint(int i) { printf("%d\n", i); } int main()...
What is the output of the following c program. Why, Can you tell me how do you solve it? #include <stdio.h> int fun(int n) { if(n==0) { return 1; } else return 7 + fun(n-2); } int main() { printf("%d", fun (4)); return 0; | }