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));
I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle): L Enter an integer length between 1 and 25: 13 ************* Which shape (L-line, T-triangle, R-rectangle): t Enter an integer base length between 3 and 25: 5 * ** *** **** ***** Which shape (L-line, T-triangle, R-rectangle): r Enter an integer width and height between 2 and 25: 4 5 **** **** **** **** **** Here's my code: #include <stdio.h> #include <ctype.h> const int...
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 program Your teacher want to find out who is the most hardworking student in class! They want to input the names according to the order they fell asleep, then print their names in the reverse order. Although you can create an array large enough to store all names, your teacher don’t want to waste our precious memory! The first line of the input is an integer x, which indicate the number of students in class. Then there are x...
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...
Given the following code: public static void foo3(String s) { if (s.length() >0) { System.out.print(s.charAt(s.length() -1)); foo3(s.substring(0, s.length() -1)); } } What is the output of: foo3(“”); 2, You coded the following in the file Test.java : System.out.println( foo(5)); //more code here public static int foo(int n) //line 9 { if (n = = 0) return 1; else System.out.println(n* foo(n-1) ); } //line 15 At compile time, you get the following error: Text.java: 15: missing return statement } ...
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?
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;...