Which of these is the correct initialization method for the following: typedef char *string;

Initialization and assignment are two distinct (but similar) things.

You can initialize an array by providing a value for it when you declare/define it.

You cannot assign to an array.

You can copy a value into an array using memcpy or strcpy:

char name[20]; strcpy(name, "Test";

But for your purposes, you can initialize the array as part of the initialization of the structure:

typedef struct { char id[10]; char name[20]; } Employee; Employee salesManager = { "A12345678", "Test" }; /* OR */ Employee salesManager = { .id = "A12345678", .name = "Test" };

Since you're asking about C++ rather than C, it's probably better to use std::string rather than raw character arrays. std::string is a lot more flexible: you can assign values, including string literals, to std::string objects.

Here you can find Typedef C Questions and Answers.

Why Typedef C Questions and Answers Required?

In this Typedef C Questions and Answers section you can learn and practice Typedef C Questions and Answers to improve your skills in order to face technical inerview conducted by Banks. By Practicing these interview questions, you can easily crack any Bank Exams interview.

Where can I get Typedef C Questions and Answers?

AllIndiaExams provides you lots Typedef C Questions and Answers with proper explanation. Fully solved examples with detailed answer description. All students, freshers can download Typedef C Questions and Answers as PDF files and eBooks.

How to solve these Typedef C Questions and Answers?

You no need to worry, we have given lots of Typedef C Questions and Answers and also we have provided lots of FAQ's to quickly answer the questions in the Bank Exams interview.

Typedef C Questions & Answers

1. The correct syntax to use Typedef C for struct is.

Typedef C Questions & Answers

2. For the following expression to work, which option should be selected. string p = “HELLO”;

Typedef C Questions & Answers

3. Which of the given option is the correct method for initialization? Typedef C char *string;

Typedef C Questions & Answers

4. Which of the following is FALSE about Typedef C?

Typedef C Questions & Answers

5. Typedef C which of the following may create problem in the program?

Typedef C Questions & Answers

6. Typedef C int (*PFI)(char *, char *)creates:

Typedef C Questions & Answers

7. Typedef C declaration:

Typedef C Questions & Answers

8. What is the output of this C code? Typedef C struct p { int x, y; }k; int main() { struct p p = {1, 2}; k k1 = p; printf("%d\n", k1.x); }

C helps anyone preparing for Sony and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear Sony interviews on C Programming language.

Here is a listing of C Objective Questions on “Typedefs” along with answers, explanations and/or solutions:

1. Which is the correct syntax to use typedef for struct?
a)

typedef struct temp { int a; }TEMP;

b)

typedef struct { int a; }TEMP;

c)

struct temp { int a; }; typedef struct temp TEMP;

d) All of the mentioned
Answer: d
Clarification: None.

2. Which option should be selected to work the following C expression?

a) typedef char [] string;b) typedef char *string;c) typedef char [] string; and typedef char *string;d) Such expression cannot be generated in C

Answer: b
Clarification: None.

1.*string *p = “Hello”;

2.string p = “Hello”;

3.*string p = ‘A’;

4.Not more than one space should be given when using typedef

Answer:2

Posted Date:-2021-02-20 21:43:50

Which of these is the correct initialization method for the following: typedef char *string;
Which of these is the correct initialization method for the following: typedef char *string;
DownloadApp

Home » C Programming » Typedef » Question

  1. Which of the given option is the correct method for initialization?
    typedef char *string;

    1. Not more than one space should be given when using typedef
    2. *string *q = “Welcome”;
    3. string p = “Welcome”;
    4. *string p = ‘B’;
    5. None of these

*string p = ‘A’;

Which of these is the correct initialization method for the following: typedef char *string;

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Typedefs – 2”.

Pre-requisite for C Typedefs MCQ set: Video Tutorial on C Typedefs.

1. Which is the correct syntax to use typedef for struct?
a)

typedef struct temp { int a; }TEMP;

b)

Note: Join free Sanfoundry classes at Telegram or Youtube

typedef struct { int a; }TEMP;

c)

struct temp { int a; }; typedef struct temp TEMP;

d) All of the mentioned
View Answer

Answer: d
Explanation: None.

2. Which option should be selected to work the following C expression?

a) typedef char [] string; b) typedef char *string; c) typedef char [] string; and typedef char *string; d) Such expression cannot be generated in C

View Answer

Answer: b
Explanation: None.

3. Which of the given option is the correct method for initialization?

a) *string *p = “Hello”; b) string p = “Hello”; c) *string p = ‘A’; d) Not more than one space should be given when using typedef

View Answer

Answer: b
Explanation: None.

4. Which of the following is false about typedef? a) typedef follow scope rules b) typedef defined substitutes can be redefined again. (Eg: typedef char a; typedef int a;) c) You cannot typedef a typedef with other term d) All of the mentioned

View Answer

Answer: b
Explanation: None.

5. Which of the following may create problem in the typedef program? a) ; b) printf/scanf c) Arithmetic operators d) All of the mentioned

View Answer

Answer: d
Explanation: None.

6. typedef int (*PFI)(char *, char *)creates ___________ a) type PFI, for pointer to function (of two char * arguments) returning int b) error c) type PFI, function (of two char * arguments) returning int d) type PFI, for pointer

View Answer

Answer: a
Explanation: None.

7. What is typedef declaration? a) Does not create a new type b) It merely adds a new name for some existing type c) Does not create a new type, It merely adds a new name for some existing type d) None of the mentioned

View Answer

Answer: c
Explanation: None.

8. What will be the output of the following C code?

  1. #include <stdio.h>
  2. typedef struct student
  3. {
  4. char *a;
  5. }stu;
  6. void main()
  7. {
  8. stu s;
  9. s.a = "hi";
  10. printf("%s", s.a);
  11. }s

a) Compile time error b) Varies c) hi d) h

View Answer

Answer: a
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

  • Get Free Certificate of Merit in C Programming
  • Participate in C Programming Certification Contest
  • Become a Top Ranker in C Programming
  • Take C Programming Tests
  • Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  • Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Which of these is the correct initialization method for the following: typedef char *string;

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.