Char initialization


 
Thread Tools Search this Thread
Top Forums Programming Char initialization
# 1  
Old 02-26-2009
Char initialization

Hi All,

char a[5]="\0";

a) a[0] contains \0
a[1] contains garbage value

b) a[0] contains \
a[1] contains 0
a[2] contains garbage value

Pls, let me know correct result is a or b. I guess a.

Thanks,
NagaSmilie
# 2  
Old 02-26-2009
There's a simpler way for you to do your homework. Write a C program with this case and let it print out the (numeric) values of the array. Compile, run, learn.
# 3  
Old 02-26-2009
I have to agree with pludi. You are asking a homework question. Please try it out on your own and see the results for yourself.

Closing this thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable initialization

Hallo Team, I have a simple request and i would appreciate your help. I would like to use two dates in my script lets: A=$(date +"%d %B %Y") echo $A 23 June 2014 That's awesome now we cooking. Now i want B to be on the previous month eg: echo $B Should give me 23 May 2014 I would... (9 Replies)
Discussion started by: kekanap
9 Replies

2. Programming

Invalid conversion from char* to char

Pointers are seeming to get the best of me and I get that error in my program. Here is the code #include <stdio.h> #include <stdlib.h> #include <string.h> #define REPORTHEADING1 " Employee Pay Hours Gross Tax Net\n" #define REPORTHEADING2 " Name ... (1 Reply)
Discussion started by: Plum
1 Replies

3. Shell Programming and Scripting

Initialization error

new to shell scripting. below line is showing error in script. ${parameter:=word} in the o/p first it shows the below error. word: not found. and then in next line print "word" ---------------- p2: word: not found. word --------------------------- OS is AIX and shell is... (12 Replies)
Discussion started by: scriptor
12 Replies

4. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

5. Programming

concat const char * with char *

hello everybody! i have aproblem! i dont know how to concatenate const char* with char const char *buffer; char *b; sprintf(b,"result.txt"); strcat(buffer,b); thanx in advance (4 Replies)
Discussion started by: nicos
4 Replies

6. Programming

Adding a single char to a char pointer.

Hello, I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it: char* getext(char *file) { char *extension; int i, j;... (5 Replies)
Discussion started by: pallak7
5 Replies

7. Shell Programming and Scripting

How to replace any char with newline char.

Hi, How to replace any character in a file with a newline character using sed .. Ex: To replace ',' with newline Input: abcd,efgh,ijkl,mnop Output: abcd efgh ijkl mnop Thnx in advance. Regards, Sasidhar (5 Replies)
Discussion started by: mightysam
5 Replies

8. UNIX for Dummies Questions & Answers

Shell initialization files

As you know, when a user logs in, the shell reads the initialization files in an order something like below... ################### Bourne Shell /etc/profile > $HOME/.profile Bash Shell /etc/profile > $HOME/.bash_profile > $HOME/.bash_login > $HOME/.profile > $HOME/.bashrc C Shell... (3 Replies)
Discussion started by: SeanWuzHere
3 Replies

9. UNIX for Dummies Questions & Answers

Help regarding storing the initialization parameters

Hi all, In my shell script, I am reading some files, processing them, and writing the out-put in the log files. The out put contains number of rows in the file etc. I want to fetch the input files from a particular directory and I want to write the logs in a particular directory with a particular... (1 Reply)
Discussion started by: VENC22
1 Replies

10. Programming

Struct Initialization

Hi We are using a code generator for initializing structures with the #define macro. Compiling it with the GCC 2.8.1 (with -ansi) it OK. But when we are using the SUN C 5.0 compiler it screams. Following is a code sample: #include <stdlib.h> #include <stdio.h> typedef struct TEST3 {... (4 Replies)
Discussion started by: amatsaka
4 Replies
Login or Register to Ask a Question