0% found this document useful (0 votes)
43 views4 pages

Arrays String

The document presents a series of C programming code snippets, each followed by a question asking for the predicted output. The code examples cover various topics such as string manipulation, array access, and pointer arithmetic. The reader is expected to analyze the code and determine the outputs based on their understanding of C programming.

Uploaded by

blocklearn0903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views4 pages

Arrays String

The document presents a series of C programming code snippets, each followed by a question asking for the predicted output. The code examples cover various topics such as string manipulation, array access, and pointer arithmetic. The reader is expected to analyze the code and determine the outputs based on their understanding of C programming.

Uploaded by

blocklearn0903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

What will be output of the following C code where we copy an array ‘a’ into array ‘b’ and then
the array ‘b’ into ‘a’?

#include<stdio.h>

#include<string.h>

main()

char a[] = "hell";

char b[] = "hello";

strcpy(b, a);

strcpy(a, b);

printf("%s, %s", a, b);

2. Predict the Output

#include <stdio.h>

int main() {

char *str = "hello";

str[0] = 'H';

printf("%s", str);

return 0;

What will be the output?

3. Identify the Output

#include <stdio.h>

int main() {

int arr[] = {10, 20, 30, 40, 50};

printf("%d", 2[arr]);

return 0;

What will be the output?

4. Predict the Output


#include <stdio.h>

#include <string.h>

int main() {

char str1[] = "hello";

char str2[] = "hello";

if (str1 == str2)

printf("Equal");

else

printf("Not Equal");

return 0;

What will be the output?

5. Predict the Output (sizeof with String Literal)

#include <stdio.h>

int main() {

printf("%lu", sizeof("abc"));

return 0;

What is the output?

6. Predict the array with 2D Array Access

#include <stdio.h>

int main() {

int arr[2][2] = {{1, 2}, {3, 4}};

printf("%d", *(*arr + 3));

return 0;

What will be the output?

7. Predict the output

#include <stdio.h>

int main() {

char str[] = {'H', 'e', 'l', 'l', 'o', '\0'};


printf("%c", str[5]);

return 0;

What is the output?

8. Predict the output

#include <stdio.h>

#include <string.h>

int main() {

char str[] = "abc";

printf("%lu %lu", sizeof(str), strlen(str));

return 0;

9. Predict the output

#include <stdio.h>

int main() {

char *str[] = {"Hello", "World"};

printf("%c", *(*(str+1)+1));

return 0;

10.Predict the output:

#include <stdio.h>

int main() {

char *msg[] = {"Hi", "There", "Coder"};

char **p = msg;

p++;

printf("%c\n", *(*(p) + 2));

return 0;

11.Predict the output:

#include <stdio.h>

int main() {
char *nums[] = {"One", "Two", "Three"};

char **p = nums + 1;

printf("%c\n", *(*p + 2));

return 0;

12. Predict the Output (Reverse Access)

#include <stdio.h>

int main() {

char *fruits[] = {"Apple", "Banana", "Mango"};

printf("%c\n", fruits[2][-2]);

return 0;

13. Predict the Output (Character Skipping)

#include <stdio.h>

int main() {

char *langs[] = {"C", "Python", "Java"};

printf("%s\n", langs[1] + 2);

return 0;

You might also like