Questions
SP25: CS-149 Sec 03 - Operating Systems CS149 Andreopoulos, Spring 2025 -- Final Exam
Single choice
What is the output of this C program (assume a pointer is 8 bytes)? #include <stdio.h> #include <string.h> int main() { char *str = "Hello"; printf("%ld, %ld\n", strlen(str), sizeof(str)); return 0; }
Options
A.5, 8
B.6, 8
C.10, 20
D.8, 5
View Explanation
Verified Answer
Please login to view
Step-by-Step Analysis
Here we analyze what the program prints by examining the two expressions inside printf.
Option by option, we consider the behavior of strlen and sizeof in this context.
First, strlen(str): Since str is a pointer to the string literal "Hello", strlen computes the length of the string up to the terminating null character. The string "Hello" consists of 5 visible characters: H, e, l, l, o, and then a null......Login to view full explanationLog in for full answers
We've collected over 50,000 authentic exam questions and detailed explanations from around the globe. Log in now and get instant access to the answers!
Similar Questions
What is the correct syntax to declare a pointer to an array of 10 integers?
What is the output (to stdout) of this C code, if all these lines execute on the CPU uninterrupted?
What do these printf statements in the functions print?
In a consumer society, many adults channel creativity into buying things
More Practical Tools for Students Powered by AI Study Helper
Making Your Study Simpler
Join us and instantly unlock extensive past papers & exclusive solutions to get a head start on your studies!