If the kernel (cokernel) of a morphism $f$ is trivial, then is $f$ injective (surjective), or mono (epi)?

Define a monomorphism (epimorphism) as a left-cancellative (right-cancellative) morphism, in some category.

The Wikipedia page on cokernels says that a morphism is injective (surjective) iff its kernel (cokernel) is trivial. The category being discussed seems to be that of vector spaces.

Now, in many categories, being an injection (surjection) is equivalent to being a monomorphism (epimorphism), but, if this is not the case --ie. monomorphisms are not injective (epimorphisms are not surjective)--, does the above result generalize to such monomorphisms (epimorphisms)?

Namely, is the following true? A morphism is a monomorphism (epimorphism) iff its kernel (cokernel) is trivial.

• A category need not have kernels at all. The typical kinds of categories that are considered where kernels behave like they do in e.g. the category of vector spaces are abelian categories. In abelian categories, it is indeed the case that the monomorphisms are exactly the kernels (and dually for epimorphisms and cokernels). Admittedly, the Wikipedia definition almost takes this as part of the definition. Jun 6, 2017 at 21:10
• It's much more common for injective to be equivalent to monomorphic, than for surjective to be equivalent to epimorphic, in concrete categories. Counterexample for the latter: in the category of rings, the inclusion $\mathbb{Z} \to \mathbb{Q}$ is an epimorphism; and in general, the inclusion of an integral domain in its field of fractions is an epimorphism. Jun 6, 2017 at 21:11
• Kernels and cokernels don't make sense in an arbitrary category. The right statement in an arbitrary category involves a generalization called the kernel pair resp. the cokernel pair. Jun 6, 2017 at 21:15

If you have a category with a zero object, then a monomorphism $$f$$ has zero kernel: $$f\circ\ker f = 0 = f\circ 0\implies \ker f = 0$$. This doesn't show that the kernel actually exists, just that if it does, it must be equal to zero. However, it is not difficult to verify that $$0$$ satisfies the universal property of the kernel in this case. Reverse all the arrows to get the dual statement for cokernels.
However, the converse is false: consider the category with four objects $$A$$, $$B$$, $$C$$, and a zero object $$0$$ and morphisms \begin{align*} \operatorname{Hom}(X,X) &= \{0, id_X\}\quad\textrm{for each object }X\\ \operatorname{Hom}(B,C) &= \{0, f\}\\ \operatorname{Hom}(A,B) &= \{0,g,h\}\\ \operatorname{Hom}(A,C) &= \{0, fg = fh\}\\ \operatorname{Hom}(C,A) &= \operatorname{Hom}(C,B) = \operatorname{Hom}(B,A) =\{0\}. \end{align*} By construction, $$g\neq h$$, $$fg = fh$$, and you can verify that $$\ker f$$ exists and is equal to $$0 : 0\to X$$.
I just wanted to supplement the existing answer to this question with another example of a category with a zero object and kernels, where a morphism with trivial kernel need not be monic. The category I have in mind is the category $$\mathbf{Set}_*$$ of pointed sets, whose objects are sets $$X$$ with a labelled element $$*\in X$$, and morphisms are functions that preserve the labelled element. This category has a zero object as well as kernels (in fact, all limits and colimits). The zero object is the singleton set $$\{*\}$$, and the kernel of a morphism $$f\colon X\rightarrow Y$$ is the preimage of $$*\in Y$$, with its labelled element being the same as in $$X$$. The monomorphisms in $$\mathbf{Set}_*$$ are exactly the injective functions.
Morphisms in $$\mathbf{Set}_*$$ with trivial kernel need not be monic. The simplest example is to take the function $$f\colon\{*,x,y\}\rightarrow\{*,z\}$$ sending $$*$$ to $$*$$ and $$x$$ and $$y$$ to $$z$$. This has trivial kernel but is not monic.