Declare a char array called alpha, and initialize it to the string \"ABCDEFGHIJK
ID: 3848623 • Letter: D
Question
Declare a char array called alpha, and initialize it to the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ". In your declaration, make the alphabet array read - only, so none of the letters in the array can be changed later in the program. Given a char pointer called ptr (i.e. char * ptr) and the alpha array declared in problem (1) above, make ptr point to the letter 'D' in the alpha array (i.e. set ptr to the memory address where 'D' is stored). What's wrong with the code below? (Circle the line with the error, and describe the error) int * int_ptr; int primes [] = {2, 3, 5, 7}; int composite [] = {4, 6, 8, 9}; int_ptr = primes; composite = int_ptr; Pointers enable passing variables to functions by: A. Pass by value B. Pass by reference C. Pass by number D. Pass by operator What is printed to the screen by the code below? int number [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; for (int i = 1; iExplanation / Answer
1 & 2.
#include <stdio.h>
int main()
{
//PART 1
const char alphabets[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //read only char array
for(int i=0;i<26;i++)
printf("%c ",alphabets[i]); //printing alphabets
printf(" ");
//PART2
const char *ptr; //char pointer
ptr = &alphabets[3]; //pointing char pointer to 'D'
//printf("%c ",*ptr);
return 0;
}
3.
Error at line : composite = int_ptr;
You can assign the pointer to array. In that case, pointer will hold the first position of the array.
But you cannot point the single pointer to array. If you want to copy, you need to do it by looping.
4.
a. Pass by Value
C supports only pass by value when pointers enable passing variables to functions.
5.
OUTPUT:
2 2
6 6
10 10
14 14
18 18
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.