1. Output:
5
20
In this particular program, we have created an array 'A' of type integer. Then we created an integer pointer 'ptr1' which points to the 1st element of array 'A' . Then we created 2nd integer pointer 'ptr2' and assign memory location of 6th block from the 1st array element(This is valid declaration in C). As the int size is taken as 4, so when we execute the first print statement,then each element will occupy 4 bytes of memory and and there are 5 blocks of memory between the 2 pointers memory location as 'ptr1' is pointing to 1st element and 'ptr2' is pointing to 6th. So 'ptr2-ptr1' .gives the 5 as there are 5 elements between them. But in the next print statement, we type cast the pointer variables to char,so they started pointing to individual addresses in momory. So the difference between '(char*)ptr2 - (char*)ptr1' gives 5 * 4 (size of int ) memory locations i.e. 20.
2. Output:
1
4
9
16
25
36
49
64
81
100
Total is: 385
In this program, we have created 3 unsigned integer variables(means they can only take positive values), x initialized to 1, total initialized to 0 and y only declared not initialized. When while loop executes, it checks if value of x is less than or equal to 10, if yes it goes inside the loop, First it stores square of x in y and prints y, Then value of y gets added to total which was initially 0, then post increment of x will increment x by 1. This while loop will continue until x is not greater than 10. Each time it prints square of current value of x which gets stored in y, adds that y value to total and increment x. When we come out of loop, value of total will be printed which is equal to sum of squares of x values from 1 to 10.
PART FOUR:(20 points) Predict the output that would be shown in the terminal window when the...
PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...
(Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byte unsigned int variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an unsigned int variable, assign the first character to the unsigned intvariable, shift the unsigned int variable left by 8 bit positions and combine the unsigned variable with the second character using the bitwise inclusive OR operator....
P1) Write a complete C program that prints out the word YES, if its string command line argument contains the sequence the somewhere in it. It prints out the word NO otherwise. Both the word the and partial sequences like in the words theatre or brother qualify. Note: You can use string functions or not but if you do the only ones allowed are strcpy and strlen. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P2) What is the output of the following program (one answer per...
Q4) what is the output after the code below is executed? #include <stdio.h> #1 nclude<string.h> int main) char abc[100]-"Good Luck in Your Programming Final" int i, ; while(abc[i]!= '\0'){ if(abc[i]' if(abc[i+1]-'&&abci+1] -'0' else printf"c", abcli-1]) printf("\n w = %d return 0; \n", w); Place you answer here 4 l Page
Part D. On executing the below program, what will be the output of the following program if the source file contains a line "This is a sample."? [5 marks] #include <stdio.h> int main() { char ch; int k, n=0; FILE * fs = fopen("source.txt", "r"); while(1) { ch = fgetc(fs); if(ch == EOF) break; else { for(k=0;k<4;k++) fgetc(fs); printf("%c", ch); n += k; } } printf("%d\n", n); fclose(fs); return 0; } ---------------------------------- Any one can explain the question to me...
22. (6 points) Determine the output for the following coe # include < stdio.h > int main(void) ( int z 1, total -0, y printf(d , x) ) //end-for printf("The total %d\n", total) ) //end-main
Enter a sentence:There Enter word to be found:re re is found. What is my misttake?Can you edit the code? #include <stdio.h> #include <string.h> int main() { char sent[100],search[100],*ptr; int count=0; printf("Enter a sentence: "); gets(sent); printf("Enter word to be found: "); gets(search); ptr=strstr(sent,search); while(ptr!=NULL) { count++; ptr++; ptr=strstr(ptr,search); } printf("%s",ptr); return 0; }
ANSWER ASAP PLEASE IN C Duplicate the program below to a new Program 2, and modify Program 2 such that it generates n random virtual addresses between 0 and 232-1 and computes the page number and offset for each address. Here, do not write to the console. Instead, run your program with n = 1000000 random virtual addresses and compute the total CPU time of the task. Report your findings, as well as how you ran your program. Provide commentary...
what is the output of the following program? #include<stdio.h> #include<string.h> int main(void){ char word[20]; int i =0 strcpy(word, "ORGANISE"); while(word[i] !='\0'){ if(i%2 ==1) word[i] = 'C'; i++; } printf("%s",word); return 0; }
Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){ char str[1000], ch; int i, frequency = 0; clock_t t; struct timespec ts, ts2; printf("Enter a string: "); gets(str); int len = strlen(str); printf("Enter a character...